Sep 26 2008
How to add a search function to NextGen gallery wordpress plugin

Strict Standards: Only variables should be passed by reference in /home/clients/56e2f1092650a93981e5ea2ac69b6745/web/blog/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_singlepic/package.module.nextgen_basic_singlepic.php on line 25

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?

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.

Votez pour ce message :
(3 vote(s), moyenne : 6,00 )
Classé sous : blog,Computering,wordpress   Tags :

| RSS 2.0 des commentaires

62 commentaires sur “How to add a search function to NextGen gallery wordpress plugin”

  1. Merci bcp pr les tips pr la recherche sur les images.
    Une question, je voudrais aussi rechercher ds les TAGS des images.

    Que faut t il modifier a partir de ce code

    SELECT pid,description,alttext , ????
    FROM wp_ngg_pictures



Laisser une réponse