• I’m setting up my navigation bar so the active page gets highlighted. I have an item called “Past Blogs” on my navigation bar which links to a category. No matter what I try, I can’t get “Past Blogs” to highlight. I can get every other tab to highlight, just not this one.

    Here’s how my code is set up currently:

    <li<?php if ( is_home()){echo " class=\"current_page_item\"";}?>><a href="<?php bloginfo('url') ?>" title="Home">Home</a></li>
    <?php wp_list_pages("depth=1&title_li="); ?>

    I’ve tried adding “is_category()” like this:

    <li<?php if ( is_home()||is_category()){echo " class=\"current_page_item\"";}?>><a href="<?php bloginfo('url') ?>" title="Home">Home</a></li>
    <?php wp_list_pages("depth=1&title_li="); ?>

    …but that didn’t work. Instead it made it so that when I click on “Past Blogs”, the current_page_item goes to the home page.

    I’m all out of ideas and would really appreciate any help! Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • So which part makes the link for Past Blogs, i see no categories or Past Blogs link in the code you’ve posted above..

    Your menu has a home link (the first line), then links to pages wp_list_pages( , so where’s the other link?

    Thread Starter cpkid2

    (@cpkid2)

    I guess that’s what I’m asking. What should I insert for the “Past Blogs” link to make it highlight when the page is active?

    Here you go..

    <?php $tcat = 1; // ID for the category - change to suit ?>
    <?php $category_link = get_category_link( $tcat );?>
    
    <li<?php if(is_home()) echo ' class="current_page_item"'; ?>>
    	<a href="<?php bloginfo('url') ?>" title="Home">Home</a>
    </li>
    
    <?php wp_list_pages("depth=1&title_li="); ?>
    
    <li<?php if(is_category($tcat)) echo ' class="current_page_item"'; ?>>
    	<a href="<?php echo $category_link; ?>" title="Past Blogs">Past Blogs</a>
    </li>

    Does that help?

    @t31os_

    Thank you so much – i’m using some JS to animate a line in my navigation and i successfully got it to work with pages & categories thanks to the above code.

    Could you help with one other thing?

    Is there a way to highlight the current cat when viewing a single post? Could you do it in some similar fashion so to add current_page_item to a parent category or page?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘current_page_item for category not working’ is closed to new replies.