Hi Everyone,
I'm hoping someone might be able to help. I'm building my site at the moment, and wish to make use of the fantastic NextGEN Gallery.
I, like many others, wish to make use of its built-in tag support for navigation around the gallery's images. I've found various threads in these forums, and pages out in the wild, about this issue - there's quite a lot of advice out there, and even some code snippets to help.
Of course NextGEN incorporates its own tag-cloud function, but unfortunately out-of-the-box it's not as useful as it might be, as its behaviour is to display a list of tag links as a cloud, and then when one of them is clicked, displays a gallery comprising images with that tag, but it displays this gallery in place of the cloud itself, meaning that it can't be used in menus and widgets for simple navigation.
Now, there have been two fairly successful 'community-built' solutions to this issue; but they have their own little issues.
The first, described HERE is quite clean and simple, but due to changes in NextGEN Gallery (tags are no longer stored in wp_ngg_tags), it doesn't work.
The second, described HERE is designed around the later 'tag' implementation, but requires more pages to be created operate tag-navigation, and it still relies on the WordPress tagcloud functionality, which means we perhaps can't manipulate it as much as if we had plain links.
The two different methods are particularly fascinating to me, as when I was thinking of potential ways to implement navigation by tags, I (being for the most part a non-programmer) imagined a mehtod which has similarities with both, but differences which might perhaps make it a little cleaner/more flexible?
So.. to my little idea..
NextGEN Gallery already has a fantastic [ nggtags gallery=My tag ] shortcode which will display a gallery of images which share a specified tag; I like others decided that making use of this would save having to reinvent the wheel.
The trick of course is to populate the tag argument on that shortcode in a wordpress post or page dynamically from an input somewhere else (on a navigation menu, or in a widget etc.).
I'd created a page called 'tagview' on my blog, and with Exec-PHP installed (other php-in-page/post plugins are available), started messing around to see if I could echo a shortcode, with the tag part populated by a variable.
Much to my surprise, not only did it turn out possible, I found what I think is quite a cute way to do it - the _GET associative array.
On a separate page on my blog, I put a link to my 'tagview' page...
http://www.example.com/tagview/
...but in the href I added a variable, made up on the spot, so the actual href was something like:
http://www.example.com/tagview?imgtag=mytag
Then, in my tag view page I put the following:
`<?php
$imgtag = $_GET['imgtag'];
echo "[nggtags gallery=".$imgtag."]";
?>'
For people less familiar with programming than I, this basically takes 'mytag' off the end of the URL in the link, and uses it in the shortcode; resulting, as expected, in a gallery showing images tagged 'mytag'.
Now, the embarassing part is, that I don't have enough PHP knowledge to figure out how I get NextGEN Gallery's tags into an array, which I can then parse with a 'foreach' to echo a link for each tag.
Of course it'd be a cakewalk if they were just listed in wp_ngg_tags; but we've already established they're not, in fact now they're stored in wp_query and mixed-in with cateogries etc; so just reading each record in the table to an array won't work.
Inside the NextGEN Gallery package there are:
\functions.php
\lib\tags.php
\admin\tags.php
There's interesting code in all of these files (particularly the first two), including some which appear to do the business of separating what is an NextGEN Gallery tag from what is not inside wp_query; but I can't figure out which bits I can make use of to simply give me an array populated with tags I can then go on to manipulate however I want.
I would be extremely grateful if anyone can help me out with the (presumably small) bit of PHP to generate an array of tags!
Many thanks for reading, and any help you can offer,
Rob.
PS> This method of using GET could also be used to enable navigation of multiple and/or tags... If we generate an HTML form with checkboxes for each tag and use GET to send them to the code discussed here: NextGEN Gallery for tag AND tag(s)