Jun 9
Search in NextGen Gallery
This blog is built on Wordpress and I display my pictures using a plugin called NextGen Gallery which is written by by Alex Rabe.
As I write this post, I’m using Wordpress 2.7.1 and NextGen Gallery 1.3.3. I know this code will work with Wordpress 2.6 but you need NextGen 1.x or higher since there was a database schema change at that revision.
You may have noticed a link at the top that says “Search Image Database”. That search function is a customisation and I’m frequently asked how its done because its not built into NextGen at the moment (but I understand it is coming in a future version).
First, a bit of background reading, it started here, which links here and then it moved here.
Are you confused? Well here is how I do it, everything involved, this is with special thanks to my beautiful girlfriend Laura!
Disclaimer; I’m not a programmer but that may help in terms of the way I write…what I’m about to write!
Major Warning; backup backup backup, don’t come screaming to me if you stuff up.
Credit; This all originated from this chap whose name I don’t know. Apologies in advance for using the term “my” as I write!
Try and understand what is going on here and don’t just copy everything, its customised for my setup, it will be easier for you if you try to understand it to a basic level at least.
If you look at your folder structure, under wp-content/themes you will find your theme, in my case it’s wp-content/themes/moshblue-10.
To get the search working you initially need 3 php files in that folder, functions.php, search.php and searchform.php. Dependent on your theme they maybe there already but if one is missing you could simply copy it from the default theme folder (don’t do that just yet).
If they are already present they maybe providing a search function to the blog already so you may need to merge my code or create additional pages, again I say, backup backup backup!
searchform.php is just that, its the search form from which you initiate the search.
search.php is the page that returns the results of the search and functions.php is the search function, i.e. the code to do the search.
This is my searchform.php;
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
<label class="hidden" for="s"><?php _e('Search for:'); ?></label>
<div><input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Go" />
</div>
</form>
that’s literally all that is in the page, nothing extra. In the code see value=”Go” go to my search page and notice the button to search says “Go”…starting to make sense?
This is my search.php;
<?php
get_header();
?>
<div id="content">
Search results;
<p></p>
<?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, '6'); // put the number of pictures by row you want, if you don't want "4"
if ($nggpictures) {
echo "<h2></h2>";
echo $nggpictures;
}
}
}
?>
<p>Want to refine or do another Search?</p>
<?php include (TEMPLATEPATH . '/searchform.php'); ?>
</div>
<?php get_sidebar(); ?>
<!-- The main column ends -->
<?php get_footer(); ?>
The key thing to notice here is ngg_get_search_pictures($keywords, ‘6′), that 6 represents the number of pictures per row to return. Dependent upon your theme that may or may not work, and the size of the thumbnails will also make a difference.
Note that I have adjusted the search to only search pictures!!!! Take a look at the search.php from the default theme. If you compare you will notice that search.php returns blog results, I only want pictures so I stripped most of it out, as you can see.
In that code I’d also draw your attention to the references to searchform.php. If your theme already has a search function for blogs, its probably using searchform.php already. Lets say you want a seperate search page just for images, in that case create the second searchform page as something like searchformpic.php and also change the refernce in search.php.
Editing functions.php requires great care if it exists already because your theme may use it. In that case you can merge my code, its not hard, notice how my function is called ngg_get_search_pictures, compare the files and you will notice the structure and what to copy in and where.
This is my functions.php;
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Sidebar Top',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
## 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'
UNION
SELECT pid,description,alttext
FROM wp_ngg_pictures, wp_terms, wp_term_relationships
WHERE pid = object_id and term_id = term_taxonomy_id and
MATCH (name) AGAINST ('*$keywords*' IN BOOLEAN MODE)
AND exclude = '0'
";
$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="gallery'.$pic[pid].'">';
$out .= '<img class="ngg-gallery" style="border: .1em solid #FFFFFF" 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;
};
?>
You can see from above that the search is against the description, picture name, alt text and the picture tags.
So now we need to publish the search form. For that I’m going to refer you here for some background.
In summary create a new page called searchpage.php (or whatever suits if the name is already used), again here is my code (and note the searchform.php reference);
<?php
/*
Template Name: Search Page
*/
?>
<?php get_header();?>
<div id="content">
<p>* * * I'm still importing images so not alot here but give the search a go anyway * * *</p>
<p>Tip! Use quotation marks to refine searches, e.g. instead of Bare Island, which returns all results for Bare and for Island, you may wish to search for "Bare Island" which returns more specific results.</p>
<p>You can also use part of a word to return a greater number of results</p>
<?php include (TEMPLATEPATH . '/searchform.php'); ?>
</div>
<?php get_sidebar(); ?>
<!-- The main column ends -->
<?php get_footer(); ?>
Note the template name of “Search Page” change that if you already have a Search Page Template otherwise you wouldn’t know which one to pick in the next step.
Now upload all 4 pages to the root of your theme.
In your Wordpress admin go to Page > New > give it a title like Search Pic Database > Under attributes (right column, you may need to click on attributes to expand it) select the template “Search Page” (or whatever you called it).
Click Save and Publish and that should, in theory, be it.
No commentsMay 31
Gudge’d
It was going to be a great trip, taking a couple of days off work, diving Nelson Bay on Thursday, Solitary Islands on Friday and Fish Rock on Saturday and Sunday but by the previous Monday, the Pacific Highway was cut at Kempsey and South West Rocks was isolated. The word on the ocean was “Brown as far as you can see” so that pretty much was the end of it…except for Nelson Bay!
Mary and Gudge were in Nelson Bay from Wednesday, as well as diving they had other business to attend to and the closure of the road north disrupted that as well. They decided to stay put for a few more days so I decided to travel to NB and join them and local, Dave Harasti, for a couple of the great shore dives that the area has to offer.
The wet weather hadn’t been so severe to the rivers that feed into Port Stephens (where Nelson Bay is) but still I knew the viz wouldn’t be great…and it wasn’t! Macro was most definitely the call and I must say even if the viz was great, that would have been the call for me anyway as I needed to get a decent workout with the 100mm lens of the 5DII.
Nelson bay diving is best done on the high tide which this week meant 1 dive a day as we were not interested in early morning diving. On the Thursday we went to Fly Point and on Friday we dived the Pipeline. All day Friday and Saturday we had rain and lots of so on Saturday I choose to head back to Sydney rather than dive in water that resembled Pea Soup and anyway Gudge and Mary had to head south to Kiama.
So the camera and lens, well this was my first decent outing with the 100mm on the 5DII and of course the first thing I notice is that it isn’t a 100mm on a 40D.
At Fly Point I came across the resident Green Turtle and was comfortably able to get a shot of his/her head. Of course I could have done that with the 40D but I would have had to have been much further back to fit it, and in the 3 meter viz there would have been no chance of a keeper and I think one of the shots I took can be rated as a keeper.
At the Pipeline I was chasing much smaller subjects, Pipefish and Nudibranch but I also had an encounter with a Blue Ringed Occie. Normally these Octopus have to feel provoked or threatened to show their “True Colours”, well I didn’t do anything to this guy and he was mad!
I found the 100mm focused just as quick as on the 40D, possibly even faster, I don’t know if this is due to the full frame sensor, I doubt it but maybe? I had also hoped to try Gudges 1.4x teleconverter but alas didn’t get the opportunity. That would have brought the 100mm nearly back to what it was on a 40D but with potential challenges in low light, so I was keen to see how it would have gone, not too worry, next time.
The diving was actually a bonus as the primary reason to visit was to catch up with Gudge and meet Mary. Gudge is very well known and respected in the underwater photography scene, a great photographer and another Canon shooter with a 50D in a Subal housing with Inon strobes. Mary shoots a 400D in a Seatool housing. This was my first opportunity to see a Seatool housing and I was very impressed, particularly with its size and double O ringed ports and that new Inon S2000 is so small yet powerful, its amazing, I may look at one when I next need a strobe, and thanks Gudge for the lowdown on the rechargable batteries and testing procedure.
Needless to say several Little Creatures were consumed and it was great to have a decent gossip and hear of life in Exmouth. Of course I displayed my masterful skills in verbal diarrhea although Mary says Gudge gives me a run for my money!
Thanks all for a great couple of days break and also to Suz, Dave and Gigsy for the usual great hospitality.
Comments are off for this postMay 17
Seahorse Release
We had a great day on Sydney Harbour today with Sydney Aquarium Conservation Fund where they released a couple of dozen baby Whites Seahorses.
Dave Harasti is presently completing his PhD on seahorses and he is also the Seahorse scientist for SACF. Dave had a release at Manly Nets several months ago but it looked (you can’t be sure) like he lost a higher than expected number of Seahorses to predators.
The game plan this time round was to release the Seahorses at 3 months old when they would be much bigger and therefore less attractive to some predators and more capable of hiding from the other predators.
We boarded Hoochie Mumma at 10 am at the aquarium in Darling Harbour and took a nice leisurely cruise over to Clifton Garden’s. Hoochie Mumma is a new dive charter boat in Sydney Harbour and I was well impressed, very stable, wide, lots of room, good dive deck and converts nicely from dive boat to charter boat.
The boat was full of camera people from pro’s like George Evatt to a Channel Seven crew reporting for the nightly news so we had great fun watching all the prep work for the release and listening to interviews.
When we got to Clifton Dave then gave us a short talk on what was happening and the release got underway.
What was really cool was that Dave wore a full face mask with a mic and headset and George accompanied him with a video camera that feed straight back to the boat, so we actually watched live on the boat as the release happened and the kids had a great time asking Dave questions while he did the work (including the “Are you scared of Sharks” question).
Here are a few pics from the day;
Speaking of Dave, he also directed me to this great bit of video from Lembeh, check it out; The Muck at Night in Lembeh
This weekend I managed to get a dive in at Bare Island. This was my first dive with the Sigma 50mm macro on the 5DII. Of course on a 40D that 50mm was really (in terms of 35mm film) an 80mm lens so now on a full frame it was a true 50mm (if you know what I mean).
The 50mm very different on the 5DII, I would see myself now doing more portrait work with this lens than macro which I previously did. It is exciting, I see opportunities to learn and capture images I wasn’t going after before. I think you will be seeing more of the image to thr right from me in future.
I should add that the housing again performed well and today at Clifton as I looked closely at a couple of Ikelite housings my choice of Aquatica was once again re-inforced.
No commentsMay 10
5D MkII
Several years ago I remember stating that I though full frame sensor dSLR camera’s were the future. Well I got it wrong in that they still are a premium model, however at least I’m now operating one!
So far I have had two dives with my 5D MkII, both were reasonably deep so limited photography but I’m looking forward to a couple of long shore dives next weekend where I should get a heap of shots.
I was initially more impressed with the Aquatica housing than the camera. Its a great improvement on the 40D housing although thats now expected from Aquatica as they clearly are responsive to user feedback and requests. Highlights are a new coat of resilient paint, plenty of cogs internally and no bands, a ribbon on the internal Ikelite bulkhead (less risk of damage), a better port locking system and tripod / accessory points. The control knobs are also much improved making single finger use very easy.
I purchased my 40D housing direct from the US but I was happy to find that this time round the housing was affordable through the Aussie distributor, Scubapix. Not only was the price good but the communications and delivery were prompt and as fast as could be expected…a good win for all!
For a wide zoom I’ve gone with the Canon 17-40 L which is close to the equivalent of my old 10-22mm. A fisheye lens is also probably in the works when I win the lotto/recover from the cost of this purchase.
If you don’t know already, the 17-40 is truely 17-40mm , the 10-22 wasn’t a true 10-22 (35mm) because it was used by a cropped sensor. We multiply by 1.6 to give the full frame/35mm equivalent for a canon cropped sensor. This means my 100mm (works with both sensors) will not give me what I expected with a cropped sensor, to get the same image I now need a 160mm. To get an equivalent focal length I’m also considering adding a teleconverter to the existing lens rather than buying a new lens.
I have to say that I am really looking forward to seeing how my 50mm goes on the full frame. There really are lots of new and exciting things to learn, its great and keeping me busy.
I have also been busy keeping fit. Already I walk into and out of work which is 5km each way, do an odd run and now both Laura and myself are swimming over a km twice a week. Its been great for the weight, I’ve dropped a couple of kg (have a goal to loss 4 more) and really feel much fitter and healthier.
Its because of feeling that way that I got annoyed with the Dive Insurance mob called DAN, but you can read about that here.
So thats it for this post, I hope lots of shots next week, maybe even some video!
No comments