Searching through image tags with Nextgen Gallery
July 13th, 2009 posted in Code, Wordpress | 4 Comments »I’ve been looking at the image tags functions in Nextgen Gallery and it was painfully obvious that there should be a way in there to search images by tags using only the regular search box. While i did some research I found some solutions but they were awkward or not functioning, but with some piecing together of different code I found a way. Find the following line in your search.php file. If you don’t have a search.php file you can copy the index.php and rename it too search.php.
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
And then place the following code just below it. It basically adds the [nggGalleryTags] shortcode to the page and lists the pictures using NGG formatting on the page.
<?php
if(is_search()) {
$search = $wp_query-&amp;gt;get('s');
$keywords = preg_replace('/\+/',' ',$search);
if (function_exists ('nggShowGalleryTags')) {
$nggpictures = nggShowGalleryTags($keywords);
if ($nggpictures) {
echo "<h2>Pictures</h2>"
echo $nggpictures;
}
}
}
?>;
If you type some keywords in the standard searchbox you will see that it lists an additional search results with your images.