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


  #1  
Old Apr 30, 2009, 01:56 AM
drewpasmith
 
18 posts · Mar 2009
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
  #2  
Old May 13, 2009, 05:07 AM
drewpasmith
 
18 posts · Mar 2009
*Bump* Anyone?
  #3  
Old May 13, 2009, 07:57 PM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
Make a copy of index.php as search.php and put the code there.

Wrap both pieces of code into opening and closing php tags
<?php ... ?>

For the 2nd code, for functions.php, make sure you don't create blank lines anywhere outside of opening and closing PHP tags, anywhere in functions.php
  #4  
Old Jun 9, 2009, 01:15 PM
digimarc
 
1 posts · Jun 2009
I have been fighting with this for days now and not getting any image results back. I think I found a fix. I have adjusted it below. The important part is the $wpdb->prefix statement. Combined with the information from Flynn, I got everything working, finally!

Code:
FROM " .$wpdb->prefix. "ngg_pictures
Code:
/** 
** Function to do searchs on gallery pics from NextGen Gallery plugin
**
** @keywords		keywords, usually gave by the standard search query from wordpress
** @numberPicCol	number of pic by row. If null, it takes 4 by default
*/
function ngg_get_search_pictures ($keywords, $numberPicRow = NULL) {
	global $wpdb;
	$count=1; 
	if (!$numberPicRow) { $numberPicRow = "4"; }

	$nngquery = $wpdb->prepare( "
				SELECT pid,description,alttext
				FROM " .$wpdb->prefix. "ngg_pictures
				WHERE MATCH (description, filename, alttext) AGAINST (%s IN BOOLEAN MODE)
				AND exclude != 1"
				, "*".$keywords."*");
	$pictures = $wpdb->get_results($nngquery, ARRAY_A);

	if ($pictures) foreach($pictures as $pic) { 
				
		$out .= '<a href="'.nggGallery::get_image_url($pic["pid"]).'" title="'.stripslashes($pic[description]).'" class="thickbox" rel="singlepic'.$pic[pid].'">';
		$out .=  '<img class="ngg-singlepic" src="'.nggGallery::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;
};
  #5  
Old Aug 24, 2009, 08:06 PM
thirdpotato
 
1 posts · Aug 2009
Hey I just got a syntax error when I entered your new edited code below. What am I doing wrong? I added the stuff you said, in the search.php then in functions.php I just copy and pasted the last box of coding you've posted. So what do I do?
  #6  
Old Sep 28, 2009, 11:28 AM
flieger28
 
3 posts · Jun 2009
Maybe someone could post a sample search.php ?
And i don't understand how to put the search.php on the Menu on my page.
Or should I make a New Page in Wordpress, called Search and copy the content of the index.php and the code in it?
  #7  
Old Feb 3, 2010, 01:56 PM
allforoneinsultz
 
1 posts · Feb 2010
[quote=Flynn;6611]Make a copy of index.php as search.php and put the code there.
Wrap both pieces of code into opening and closing php tags
<?php ... ?>

Soooooooooo That would be like this?.............?
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/

/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
?><?php
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;
}
}
}
php?>

For the 2nd code, for functions.php, make sure you don't create blank lines anywhere outside of opening and closing PHP tags, anywhere in functions.php

Where Exactly should I put this in the code?[/QUOTE]



[quote=digimarc;8160]I have been fighting with this for days now and not getting any image results back. I think I found a fix. I have adjusted it below. The important part is the $wpdb->prefix statement. Combined with the information from Flynn, I got everything working, finally!
QUOTE]

If you understand my problem written above here.. then please explain me how you did manage to get it working.


Thanks,

Cerafil
  #8  
Old Feb 14, 2010, 07:35 AM
Davidson
 
2 posts · Jan 2010
Will you be adding a search capability to the new update. ... like the search fonction of wordpress search into NextGen Gallery pictures too.............

Last edited by juggledad; Feb 15, 2010 at 12:56 PM.
  #9  
Old Jun 15, 2011, 11:16 AM
mutpowr
 
2 posts · Jun 2011
Sorry for the necro post but im working on adding this as well. Does anyone know where he meant the

Code:
FROM " .$wpdb->prefix. "ngg_pictures
code to go?
  #10  
Old Jun 15, 2011, 11:29 AM
mutpowr
 
2 posts · Jun 2011
So i got it working just so everyone knows and i wanted to add some small tid bits to help others having this problem.

1) Go to the atahualpa theme folder and copy index.php and rename it to search.php

2) In search.php

Find:

Code:
<?php /* If there are any posts: */
Before add:

Code:
<?php 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;	
		} 
	}
} ?>
3) Find functions.php in the atahualpa theme folder

4) In Functions.php

Find:

Code:
<?php
Before Add:

Code:
<?php /** 
** Function to do searchs on gallery pics from NextGen Gallery plugin
**
** @keywords		keywords, usually gave by the standard search query from wordpress
** @numberPicCol	number of pic by row. If null, it takes 4 by default
*/
function ngg_get_search_pictures ($keywords, $numberPicRow = NULL) {
	global $wpdb;
	$count=1; 
	if (!$numberPicRow) { $numberPicRow = "4"; }

	$nngquery = $wpdb->prepare( "
				SELECT pid,description,alttext
				FROM " .$wpdb->prefix. "ngg_pictures
				WHERE MATCH (description, filename, alttext) AGAINST (%s IN BOOLEAN MODE)
				AND exclude != 1"
				, "*".$keywords."*");
	$pictures = $wpdb->get_results($nngquery, ARRAY_A);

	if ($pictures) foreach($pictures as $pic) { 
				
		$out .= '<a href="'.nggGallery::get_image_url($pic["pid"]).'" title="'.stripslashes($pic[description]).'" class="thickbox" rel="singlepic'.$pic[pid].'">';
		$out .=  '<img class="ngg-singlepic" src="'.nggGallery::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;
};?>
Note - The only problem i can find is when you search you may get the error that the item hasnt been found. However the images will still show relating to the search. So not sure on how to fix that one just yet but here is the fix im sure people would want.
  #11  
Old Jun 17, 2011, 07:48 AM
lmilesw's Avatar
lmilesw
 
10,176 posts · Jul 2009
Central New York State USA
The latest version of NextGen has support for XML sitemaps if you use Yoast's SEO plugin.
__________________
~Larry (CNY Web Designs)
This site should be a membership site since it so full of good stuff.
Please consider donating which gives you access to even more good stuff.

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


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


All times are GMT -6. The time now is 05:28 PM.


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