[Plugin: Smarter Navigation] smarter-navigation for dynamic menu highlighting (6 posts)

  1. HAlberts
    Posted 5 years ago #

    Hi Scribu,

    This is a really handy plugin. The nex/previous post links work just as I need them to. My question is this: can I use any functions from this plugin to return a string with the name of the referrer (not a link)? So, something like the referrer_link() function already written in, but somehow modify it to return just a string?

    The idea is this: I would like to use this string within a conditional tag, to test the referrer for a given post. I'd like to be able to use this to get the dymanic menu highlighting to work. Something along the lines of

    {echo " class=\"current_page_item\""; }

    a possible snippet from my menu:

    <?php if(is_category('Paintings' {
    echo " class=\"current_page_item\""; } ?>
    <?php elseif(referrer())='Paintings' {
    echo " class=\"current_page_item\""; } ?>>
    <a href="/category/paintings"><span>Paintings</span></a>

    My problem is that I have posts which belong to multiple categories. If the user links to a single post from a specific category page, I would like the menu tab for that category to stay highlighted (even though the single post may also belong to other categories). So basically, I just need to test the referrer if possible.

    Thanks for your help!

  2. scribu
    Posted 5 years ago #

    If you download the development version (1.2b), you can try using get_referrer_url()

  3. scribu
    Posted 5 years ago #

    In version 1.2, you can use get_referrer_category():

    function is_category_or_referrer($name) {
        return is_category($name) || $name == get_referrer_category()->name;
    <?php if ( is_category_or_referrer('Paintings') ) {
        echo " class='current_page_item'";
    } ?>
  4. HAlberts
    Posted 5 years ago #

    Thank you thank you! Just updated the plugin and it was exactly what I needed! Great plugin, I'll be using it on many more sites in the future.

  5. knauso
    Posted 5 years ago #

    can you please tell me how to use the get referrer category?
    I'm using smart nav onmy website and it's not working:
    maybe this will help?


  6. scribu
    Posted 5 years ago #

    Before get_referrer_category(), did you replace previous_post_link() with previous_post_smart() in your theme?

Topic Closed

This topic has been closed to new replies.

About this Topic