Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme » Plugins & Atahualpa »

Adding Search to NextGEN-Gallery


 
Prev Previous Post   Next Post Next
  #1  
Old Apr 30, 2009, 12:56 AM
drewpasmith
 
18 posts · Mar 2009
Adding Search to NextGEN-Gallery

Hi All,

I've found the following instructions to activate searching of tagged images in NextGEN-Gallery but I can't find the PHP file they refer to:

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)


The code for step on is

Code:
if(is_search()) {
	$search = $wp_query->get('s');
	$keywords = preg_replace('/\+/',' ',$search);
	if (function_exists ('ngg_get_search_pictures')) {  // function from functions.php
		$nggpictures = ngg_get_search_pictures($keywords, ''); // put the number of pictures by row you want, if you don't want "4"

		if ($nggpictures) {
			echo "<h2>Pictures</h2>";
			echo $nggpictures;	
		} 
	}
}

The code for step 2 is:

Code:
## Function to do searchs on gallery pics from NextGen Gallery plugin
##
## 2 vars : 	(1) $keywords (usually coming from the standard search query from wordpress)
##		(2) $numberPicCol (number of pic by row, if null it takes 4 )
function ngg_get_search_pictures ($keywords, $numberPicRow = NULL) {
	global $wpdb;
	$count=1; 
	if (!$numberPicRow) { $numberPicRow = "4"; }

	$nngquery = "
				SELECT pid,description,alttext
				FROM wp_ngg_pictures 
				WHERE MATCH (description, filename, alttext) AGAINST ('*$keywords*' IN BOOLEAN MODE)
				AND exclude = '0'
				";
	$pictures = $wpdb->get_results($nngquery, ARRAY_A);

	if ($pictures) foreach($pictures as $pic) { 
				
		$out .= '<a href="'.nggallery::get_image_url($pic[pid]).'" title="'.stripslashes($pic[description]).'" class="thickbox" rel="singlepic'.$pic[pid].'">';
		$out .=  '<img class="ngg-singlepic" src="'.nggallery::get_thumbnail_url($pic[pid]).'" alt="'.stripslashes($pic[alttext]).'" title="'.stripslashes($pic[alttext]).'" />';
		$out .=  "</a>\n"; 
				if ($count == 0) {
				$out .= "<br />";
				}
				++$count;
				$count%=$numberPicRow;
	}
	return $out;
};
Anybody know where I can find the search.php equivalent or the <?php if (have_posts()) : ?> to insert the new code after?

Cheers,

Drew
 

Bookmarks



Similar Threads
Thread Thread Starter Forum Replies Last Post
NextGEN-Gallery varkis Sidebars & Widgets 12 Jun 9, 2010 10:33 AM
[SOLVED] Gallery breaking problem with NextGEN and Atahualpa acabtp Plugins & Atahualpa 3 Jul 9, 2009 07:06 PM
NextGen Gallery qitt New Versions, & Updating 4 Jun 30, 2009 06:09 AM
[SOLVED] NextGen Gallery not showing up in right sidebar WebWeaver Plugins & Atahualpa 2 May 30, 2009 12:27 PM
Need a search for Nextgen Gallery danzibar Plugins & Atahualpa 1 May 11, 2009 06:53 AM


All times are GMT -6. The time now is 12:11 AM.


Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.