Sep 26 2008
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?

add a nextgen gallery search to wordpress

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.



Vote for this message:
1 étoile2 étoiles3 étoiles4 étoiles5 étoiles6 étoiles (3 vote(s), moyenne : 6.00 )
Loading ... Loading ...
Filed under: Computering,blog,wordpress   Tags:
Partager et découvrir :
  • Digg
  • del.icio.us
  • Technorati
  • Facebook
  • Google Bookmarks
  • MySpace
  • Netvibes
  • Twitter
  • Yahoo! Bookmarks
  • Wikio FR

| RSS 2.0 des commentaires

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



  1. Bonjour,

    Je sais que ce n’est pas le bon endroit pour parler de cela, mais je souhaiterais vous contacter concernant la traduction du plugin “quotes collection”, dont vous semblez être le traducteur “officiel”.

    J’ai remarqué que certaines expressions n’étaient pas traduites. Je les ai donc traduites et transmises à l’auteur du plugin. Je souhaiterais également vous les transmettre. Or il ne semble pas y avoir de formulaire de contact ou autre sur votre blog. Comment puis-je vous envoyer le fichier?

    Cordialement,




  2. Pls Help me. Is this Search Option not available for my Theme? or why cant I get this to work?




  3. This won’t work. No matter what I do.

    I’m assuming the following. Please help/correct if I’m wrong.

    Pasted in the themes fuctions.php the code.

    Then in the search.php (not the searchform.php)
    I pasted in after:
    the code and at the end is the:

    I have tags in my photos that are in nextgen gallery. Do a search, I get nothing.

    Thank you for reading, if I’m doing it wrong will someone please help?
    RRG




    • I made an adjustment, not thinking about the php code I pasted in. The below will make sense. Sorry about that!!

      This won’t work. No matter what I do.

      I’m assuming the following. Please help/correct if I’m wrong.

      Pasted in the themes fuctions.php the code.

      Then in the search.php (not the searchform.php)
      I pasted in after: “php if (have_posts())”
      the code and at the end is the: “while (have_posts()) : the_post()”

      I have tags in my photos that are in nextgen gallery. Do a search, I get nothing.

      Thank you for reading, if I’m doing it wrong will someone please help?
      RRG




  4. Still not working here and no Comments to help me.. Pls help me. Owner of this site.




  5. Hello? Anybody? I really want to have the same search options as this site. It is wonderfull!




  6. This is it. Where should I add the code?

    <form method="get" class="searchform" action="/”>

    <input type="text" class="text inputblur" value="” name=”s” />

    <input name="submit" value="Search" type="image" src="/images/magnifier2-gray.gif” style=”display: block; border:none; padding: 0 0 0 5px; margin: 0;” />




  7. chances are that’s what you want




  8. Hi I am on AtaHualpa Theme but I cannot find my searh.php Only (Search Form.php)

    Can you point me in the right direction pls


Leave a reply