• toma

    (@chromo2010)


    When I employ the ‘get_referrer_category’ tag with a conditional tag for creating an active link state, How can I isolate the specific category for the current ‘referrer’ ID?

    <li<?php if ( is_category('11') || get_referrer_category('11') ){ echo " class=\"current\""; } ?>><a href="/wordpress/sandbox01/?cat=11">Environmental</a></li>

    https://www.ads-software.com/extend/plugins/smarter-navigation/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author versusbassz

    (@versusbassz)

    <?php
    
    	$referrer_cat = get_referrer_category(); // returns category object
    	$referrer_cat_id = ( is_object( $referrer_cat ) ) ? $referrer_cat->term_id : false; // we take category id
    
    ?>
    
    <?php
    	$li_class = ( is_category( 11 ) || $referrer_cat_id === 11 ) ? ' current ' : '';
    ?>
    <li<?php echo $li_class; ?>>
    	<a href="/wordpress/sandbox01/?cat=11">Environmental</a>
    </li>

    I do not quite understand the question, but maybe this example will help you.

    Thread Starter toma

    (@chromo2010)

    Thanks. I am trying to grab the referer cat for the single-page to produce an active state within the header nav-list. The conditional function below works great and produces an ‘active’ state for my cat-pages of posts, but when the single-page loads for a post it drops the active state from the nav-list while the PU correctly paginates the category within the single-page.

    <li<?php if ( is_category('11') ){ echo " class=\"current\""; } ?>><a href="/wordpress/sandbox01/?cat=11">Environmental</a></li>

    I tried adding your suggestion to the header.php but cannot get the desired feature. It also breaks my active state for the category page. In my original snippet (original post), it works for both cat-pages and single-pages only ALL of the referrer-links become ‘active’ on the single-page. You have an earlier thread related to this problem but it seems no longer relevant to the current version of the PU.

    Plugin Author versusbassz

    (@versusbassz)

    How you output this nav list ( wp_nav_menu or static markup or with other wp function ) ?

    Is this primary or secondary navigation?

    In any case, on single post page you can get referrer category object by get_referrer_category() function, and when you output navigation items, you can compare any navigation item parameter with get_referrer_category() result parameters and add active class if the parameters match.
    Of course, if navigation not is static markup.

    And what is PU? =]

    Thread Starter toma

    (@chromo2010)

    The nav-list is static markup.
    This is primary header.php navigation.
    I added the following to my single-page:

    <?php $referrer_cat = get_referrer_category(); // returns category object
    $referrer_cat_id = ( is_object( $referrer_cat ) ) ? $referrer_cat->term_id : false; // we take category id
    ?>

    And edited my static link with:
    <li<?php if ( is_category( '19' ) || $referrer_cat_id === 19 ){ echo " class=\"current\""; } ?>><a href="/wordpress/sandbox01/?cat=19">Print</a></li>
    This shows the current-class correctly for the category-page, but fails for the single.php page where the referrer_cat ID is needed to create an active state.
    PU is a typo, I meant PI for ‘plug-in’, sorry.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get_referrer_category ID’ is closed to new replies.