WordPress.org

Forums

Smarter Navigation
[resolved] Tell reader that the next/previous links are browsing a specific tag/ca (9 posts)

  1. Parakoos
    Member
    Posted 3 years ago #

    Smarter Navigation allows you to create a back-link to the referring category or tag by using this code:

    <?php referrer_link(); ?>

    But this only outputs the name of the tag or category. What if you want something like this:

    Browsing the tag Awesome Stuff.
    Browsing category Photos.

    Basically, you want to output different text for tags, categories etc. Simple. Query the cookies.

    <?php if( strpos($_COOKIE['smarter-navigation']['query'], 'tag') ) { ?>
    	Browsing the tag <?php referrer_link(); ?>.
    <?php } elseif( strpos($_COOKIE['smarter-navigation']['query'], 'category') ) { ?>
    	Browsing category <?php referrer_link(); ?>.
    <?php } else { ?>
    	Browsing <?php referrer_link(); ?>.
    <?php } ?>

    You can see a working version of this at The Modern Nomad.

    http://wordpress.org/extend/plugins/smarter-navigation/

  2. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    It would be more reliable to use the decoded version of the data, instead of reading the cookie directly:

    if ( isset( Smarter_Navigation::$data['query']['category'] ) {
      ...
    } elseif ( isset( Smarter_Navigation::$data['query']['tag'] ) {
      ...
    }

    etc.

  3. Parakoos
    Member
    Posted 3 years ago #

    Thanks for the correction. Indeed, that works. However, for the category, you need to use 'category_name' and not 'category'.

    if ( isset( $query_vars['category_name'] ) {

  4. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    Actually, even more reliable would be to create a dummy WP_Query instance and use it's conditional tags:

    $q = new WP_Query;
    $q->parse_query( Smarter_Navigation::$data['query'] );
    
    if ( $q->is_category() ) {
      ...
    } elseif ( $q->is_tag() ) {
      ...
    }
  5. Parakoos
    Member
    Posted 3 years ago #

    Would that cause another expensive DB query?

  6. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    Nope, because you create the instance without any parameters and then call parse_query().

  7. Parakoos
    Member
    Posted 3 years ago #

    Yep, that works very well. Awesome!

  8. squizeers
    Member
    Posted 2 years ago #

    Looks like I am in the right discussion.
    So I installed the smarter navigation so that the posts can be navigated if they have the same tags. But there is no plugin setting page where i can manage the plugin. And I am not sure if the plugin does what i am looking for.
    Does this plugin navigate the posts whaich have same tags?

  9. ppj81
    Member
    Posted 2 years ago #

    Is there any way set a specific category? The plugin works perfect, but when a post had 2 or more categories the first category is taken. I need some way to tell modify "in_same_cat" so "in_same_cat" will be category 3.

    Is there any way to do this?

    Thank you in advance.

    Peter

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Smarter Navigation
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic