Forums

[resolved] NextGEN Gallery - My 'simple' idea for navigation by tag (6 posts)

  1. ramblingaroundtherope
    Member
    Posted 1 year ago #

    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)

  2. ramblingaroundtherope
    Member
    Posted 1 year ago #

    One quick correction... I said above that tags are now stored in wp_query, that is of course nonsense (my brains are scrambled), and they are in fact stored in wp_terms, along with categories and tags for blog posts.

  3. ramblingaroundtherope
    Member
    Posted 1 year ago #

    OK...

    I've spent a long time looking at the NextGEN Gallery PHP (with VERY limited knowledge of PHP); I've spent a long time looking at discussion threads and other sites.

    A little more staring at the PHP got me to take a second look at the database structure, which in turn lead me to (bravely!) explore the Function Reference in the WordPress Codex.

    ...Well goodness me... What a pleasing (and somewhat embarrassing) five minutes that was!..

    I pretty quickly stumbled on 'get terms' - and found that:

    '<?php
    $imgtags = get_terms( 'ngg_tag' );
    print_r ($imgtags);
    ?>'

    ...returned an array with all the lovely attributes of my gallery tags; and shortly after found that:

    '<?php

    $imgtags = get_terms( 'ngg_tag', array(
    'fields' => names
    ) );

    print_r ($imgtags);
    ?>'

    ...does exactly what I'm after, populating the array 'imgtags' with a list of tags.

    I'm now going to spend the rest of my evening joyfully playing with foreach to make links, or perhaps even checkbox forms, for my simple and flexible tag-navigation.

    I'll mark this topic complete now, and hope that perhaps my ramblings have been useful to others who are trying to work with NextGEN gallery tags in future

    Peace.

    Rob.

  4. badjesus
    Member
    Posted 1 year ago #

    Did you ever get this working with checkboxes?
    I have been messing around with this for days I can't seem to get it.
    I am not a PHP programmer by any means, but I can fumble my way through, but I can not see to get the array to work with making checkboxes and still allowing it to be searchable.

    I am interested in sharing our code and seeing if we can get this to work? It would be a pretty huge feature enhancement to NGG.

    Thanks!

  5. ramblingaroundtherope
    Member
    Posted 1 year ago #

    I sorta did... Stick a .com on me and you'll be able to see what I ended up with.

    I've not released my code because there are known limitations (bugs almost); because of my inexperience with PHP I'm doing some stuff with the array which will cause not-pretty things to happen under certain circumstances. I just opted to use it within those limitations.

    That said, I'd been meaning to drop Alex Rabe (NGG Dev) a line to see if it might be worth including (or perhaps an expertly-overhauled rework of my basic idea).. I'm replying on my phone just now so pulling the code out would be tricky at best, but have a look at what I got, in the morning (later in it anyway - I don't know where you are but it's 3AM here) I'll drop Alex an email ((1) for my paranoia about publicly releasing a 'hack' to someone else's code, and (2) in the hope that he might 'ok' it as safe/compatible (aforementioned limitation aside)), and I'll head back here with what I came up with.

    Best regards,

    Rob

  6. badjesus
    Member
    Posted 1 year ago #

    How did you get that to work, I am looking at the URL it is pulling and I can't figure out how that is actually showing all tags?

    Could you please share your code?

    This is where I am sitting if it will help anyone else.
    I can get it to pull the array of tags and search by a single checkbox, but my issue is in changing the output of the form to display all tags. It is only showing results from the last checkbox and ignoring the first two.

    <form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">

    <div>Search</div>
    <div>
    <?php
    // The following will list all tags with a checkboxes next to them.

    $nggimgtags = get_terms( 'ngg_tag', array(
    'fields' => names
    ) );

    $checkboxes = '';
    foreach($nggimgtags as $nggimgtag) :
    $checkboxes .='<input type="checkbox" name="s" value="'. $nggimgtag . '" id="s" />'. $nggimgtag . '';
    endforeach;

    echo $checkboxes;
    ?>
    </div>
    <div>

    <p><input type="submit" value="Search">

    </p>
    </form>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags