How to add a search function to NextGen gallery wordpress plugin

NextGen gallery is quite a nice plugin. But it lacks a function, a very obvious one… the possibility to search inside the pictures name, alternative text or description. Wouldn’t be nice if you can, with only one search query, display pictures from your gallery matching the searching terms, as well as you posts?

wp plugin nextgen gallery search

I’m not a coder. Not at all. But it still works like a charm. If you know how to edit you theme, here are the modifications you have to go through:

  1. Add this code in your file search.php (inside your template folder), right after
    <h2 class="pagetitle">Search Results</h2>
    or somewhere (depending your template) after
    <?php if (have_posts()) : ?>,
    otherwise it wouldn’t find the pictures. Pay a special attention to the line
    $nggpictures = ngg_get_search_pictures($keywords, '');
    since on the second function argument ( ” ) you may indicate the number of pictures you want to display on each row result. IE, if you want to get 6 pictures displayed on each row, you have to change the line to
    $nggpictures = ngg_get_search_pictures($keywords, '6');
    By default, 4 pictures for each row are displayed. Note that you may also split the code, and put a part before and another part after the <?php while […] ?> function with the result to display pictures (if relevent) even if there is no post. That’s a bit more advanced, but people with advanced php skills won’t need any complementary explanation to achieve that.
  2. Add this code (or this code if you use NexGen 1.0) anywhere in your file functions.php (inside your template folder, create one if you don’t have any)

That’s all ! Have a look to my searchbar, and see how it works. Try with “jim lobe” or click here.

0
0
Lire aussi  How to add a search function to NextGen gallery wordpress plugin

Leave a Reply