Pages

Monday, September 3, 2012

How to add gallerywise or advanced search in nextgen gallery in wordpress?

To add advance or gallery wise search need to follow below steps....

1. First we need to install both nexgengallery and nexgengallery search.
2. Then change the form structure of searchform.php in the current theme  as below..

<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<table>
<tr>
    <td><label for="s" class="assistive-text"><?php _e( 'Search', 'twentyeleven' ); ?></label></td>
    <td><input type="text" class="field" name="s" id="s" placeholder="<?php esc_attr_e( 'Search Images', 'twentyeleven' ); ?>" /></td>


    <td valign="top">
    <label for="gallery" >    <select name="gallery" id="gallery" style="border:1px solid #CCCCCC;height:28px;vertical-align:top;">
            <option value="">--All--</option>
            <?php
                while($fetchgallery=mysql_fetch_array($resultgalleries)){ ?>
                <option value="<?php echo $fetchgallery['title']?>"><?php echo $fetchgallery['title']?></option>
                <?php }
            ?>
        </select><label for="s" class="assistive-text">
    </td>
    <td><input type="submit" class="submit" name="submit" id="searchsubmit123" value="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" /></td>
</tr>
</table>

3. Search for the code in nggSearch.php( plugins/nggSearch)
$this->search_result = array_merge( (array) $nggdb->search_for_images( $wp->query_vars['s']
and replace this total function with the below code..
$this->search_result = array_merge( (array) $nggdb->search_for_images( $wp->query_vars['s'] ,$wp->query_vars['gallery']
4.  Search  for the function
function search_for_images( $request,  in ngg-db.php(plugins/nextgen-gallery/lib/) and replace that with the below code
function search_for_images( $request,$gallery123,
5. This is the main and dinal step. Search for the below code in the same file
$query = "SELECT t.*, tt.* FROM $wpdb->nggallery AS t INNER JOIN $wpdb->nggpictures AS tt ON t.gid = tt.galleryid WHERE 1=1 $search ORDER BY tt.pid ASC $limit_by";
 $result = $wpdb->get_results($query);
Here we need to take if condition because to check either gallery value coming empty or not so replace the total query with below code..

if($gallery123 == ""){//gallery name is our specific name where we are give in the function
       $query = "SELECT t.*, tt.* FROM $wpdb->nggallery AS t INNER JOIN $wpdb->nggpictures AS tt ON t.gid = tt.galleryid WHERE 1=1 $search ORDER BY tt.pid ASC $limit_by";
        $result = $wpdb->get_results($query);
        }else{
         $query="select p.*,g.* from wp_ngg_pictures p inner join wp_ngg_gallery g on p.galleryid = g.gid where title='".$gallery123."'  AND ((description LIKE '%".$request."%') OR (alttext LIKE '%".$request."%') OR (filename LIKE '%".$request."%'))";
         $result = $wpdb->get_results($query);
        }

No comments:

Post a Comment