• I am testing out a site and have run into a strange issue. Basically, I want my navigation list to give an ID of “current” if on a Portfolio page or a Portfolio category post (catID = 3 in this case). My code for my navigation is as follows:

    <li<?php if (is_home()) { echo " id=\"current\""; }?>><a href="/">home</a></li>
    <li<?php if (is_page('about')) { echo " id=\"current\""; }?>><a href="/about/">about</a></li>
    <li<?php if (is_page('portfolio')||in_category('3')) { echo " id=\"current\""; }?>><a href="/portfolio/">portfolio</a></li>
    <li<?php if (is_page('contact')) { echo " id=\"current\""; }?>><a href="/contact/">contact</a></li>

    All works well on both the Portfolio page and the Portfolio category post, however when I browse back to my homepage (index.php), my “Home” and “Portfolio” navigation links both have an ID of “current”. I’m not sure why the homepage is returning true for in_category(‘3’), but it’s frustrating me quite a bit. In-fact my index.php file only has get_header(); and get_footer(); so far with no content. So what can it be?

    Any insight or help would be appreciated, thanks!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ranji77

    (@ranji77)

    please, has anyone else experienced something like this?

    I know this is a little old now but I recently ran in to this issue and I’m pretty sure it has to do with WordPress returning the first post’s category on a page (in your case the home page was returning the first post’s category).

    I fixed it by adding an additional if not is_home check on all the non home pages like so in your example:

    if (is_page('portfolio') || in_category('3') && !is_home()) { echo " id=\"current\""; }?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘in_category is returning true on homepage (index.php)’ is closed to new replies.