• Resolved Parakoos

    (@parakoos)


    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/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author scribu

    (@scribu)

    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.

    Thread Starter Parakoos

    (@parakoos)

    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'] ) {

    Plugin Author scribu

    (@scribu)

    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() ) {
      ...
    }
    Thread Starter Parakoos

    (@parakoos)

    Would that cause another expensive DB query?

    Plugin Author scribu

    (@scribu)

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

    Thread Starter Parakoos

    (@parakoos)

    Yep, that works very well. Awesome!

    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?

    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

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: Smarter Navigation] Tell reader that the next/previous links are browsing a specific tag/ca’ is closed to new replies.