Support » Fixing WordPress » Problem with “current_page_item” navigation highlighting

  • I am using 2.1 and have successfully done dynamic navigation on several sites using “page_item” and “current_page_item” invoked by wp_list_pages(). I am having problems on one site. I have assigned the “Home” page as the static front page and a page called “Blog” as the post page alternative. For some reason, the Blog page does not dynamically highlight that navigation link because wp_list_pages() is not throwing the “current_page_item” into the HTML.

    Can anyone think of a reason why this is occurring? “Blog” is a “page”, and I see the the WP documentation says that “current_page_item” is applied as follows: “When wp_list_pages is called while displaying a Page, the list item for that Page will be given the additional class “current_page_item”. So, I have concluded that for some reason WP is not seeing the “Blog” page as a “page”. Make sense? Any help appreciated.

Viewing 15 replies - 1 through 15 (of 44 total)
  • I’m having the exact same issue. I’m assuming it has something to do with the way you acheive this effect. I’m not sure what you did, but I have a file called blog.php that is used as the blog template, and a Page called “Blog” with a slug of “blog”

    Then, I have permalinks set up to use the name based URLs and have added ‘/blog/’ to the beginning of the custom blog url.

    When a page is loaded it doesn’t use the long blog URL and correctly loads the right page. But then the blog is loaded, I’m guessing it’s using the custom permalink URL and not acually loading the “Blog” page.

    Or I could be completely wrong, but either way, the current_page_item class is not being applied properly.

    Anyone have any ideas why this would be happening? I use custom templates on other pages and they work fine.

    Thread Starter dwzemens



    What version are you using? I determined that my problem was with the newest version – New Releases: 2.1.1 and 2.0.9.

    I stumbled onto this by uploading a theme that functioned properly on a blog I control that is running on WP 2.1, but it too had the issue when running on the server with WP 2.1.1. I then loaded the theme that was originally acting incorrectly in WP 2.1.1 onto a blog that was running 2.1, and it worked correctly at that server.

    When I revert to WordPress 2.1 Ella on my original problem install the problem is resolved. So, right or wrong, I determined that the newest release was the issue.

    Let me know if that is the problem for you, too.

    I’m having the same issue where the ‘Blog’ page doesn’t have “current_page_item” included in the HTML.

    This is after going into Options > Reading > Front Page and assigning the “Home” page as the static front page and a page called “Blog” as the post page alternative

    I’m using 2.1.1

    Maybe something like this will work:

    <?php /* If this is the frontpage */ if ( $post->ID == 'x' ) { ?>
    <li id="current_page_item"><a href="<?php bloginfo('url'); ?>/?page_id=x">Page-x</a></li>
    <?php } else { ?>
    <li><a href="<?php bloginfo('url'); ?>/?page_id=x">Page-x</a></li>
    <?php } ?>

    where “x” is the page_ID.

    Thread Starter dwzemens


    azaozz, I think you are missing the point. Workarounds such as you suggest were necessary before WP 2.1 recognized a static front page. Now wp_list_pages() is designed to, and should, do this work all by itself.


    Yes, you’re right, wp_list_pages() will output nicely formatted list of all pages on your site and takes quite a few arguments. But if you want to turn this list into a more interactive menu, you’ll have to use some of the conditional tags and even some simple php to make it all look nice.

    As far as I can tell WP 2.1 now supports 2 special front pages: one is a static home page that you can select with is_home(), and the other is the usual front page that would have been displayed if you didn’t have static home page. Although it’s created as a Page, the second one is an archive listing of the most recent posts and that’s probably why wp_list_pages() doesn’t insert the extra “current_page_item” class.

    In any case you can use several ways to detect when this page is displayed, like is_page(x), is_page(Blog), $post->ID==’x’, etc. This is actually the full goodness of WP 🙂 . With very limited knowledge of php (like mine) you can make your website any way you like it.

    Thread Starter dwzemens


    I hate to disagree, but with the new version of WP no other code is necessary to facilitate the current_page_item tag. Here is all the code I use at this website that is under construction:

    <ul class=”btn”>
    <?php wp_list_pages(‘sort_column=menu_order&title_li=&exclude=’ ); ?>

    The “Home” page is the static Page assigned through the dashboard to act as the home page. No other tweaks or conditional arguments are used, just the code above. As you can see, each page invokes the current_page_item tag and the correct navigation link is highlighted.

    For some reason, which was the basis for this original post, this was not functioning correctly with the project I was referring to. I think the cause, as I mentioned in later posts, was a bad version of the new WP downloads. It works great with 2.1 Ella, but some of the more recent versions were NOT invoking current_page_item on the Home page.

    Make sense now?

    Thread Starter dwzemens


    Here is the most recent example of the problem. These two different sites are using the EXACT SAME CODE to display the pages, which is simply the wp_list_pages() function. The CSS outputs a subtle underline image below the navigation link identified as current_page_item.
    This site, just loaded today with WP 2.1.2 (newest version), DOES NOT HIGHLIGHT the “Blog Page”, which is called “News(Blog)”, because it does NOT correctly ouput the current_page_item tag as it should, which should be output by wp_list_pages().
    This site, running a clean version of WP 2.1.1 (before the cracker infection) DOES HIGHLIGHT the “Blog” page, which is called “In the News” at this website. The exact same wp_list_pages() CORRECTLY outputs the current_page_item tag at this site.

    So, the problem continues to exist and it is dependant on the version of WP being used.

    Wow, I wish I could solve this.

    Thread Starter dwzemens


    Searching the WordPress bug tracking database, the problem seems to be identified.

    If I am reading this correctly, the problem was opened months ago, closed as fixed, and reopened on Feb 27, 2007 as still existing. Is that what it looks like to you?


    I have noticed the same problem… my static “blog” page (not the same as my “home”) page does not get the “current_page_item” class on its link, and so the menu item is not highlighted.

    I have also noticed that this page doesn’t get a page title (i.e. all the pages get a title of myURL >> page title but the blog page only shows the URL with no page title).

    I saw the above post that this has been documented as a bug in 2.1.2 which is the version I’m using.

    My question is — is there a line of code I can put in my index.php file or somewhere else to fix this? I don’t want to wait for the next version of WP to fix it…

    (This is my first post here — hope I’m following protocol. And, full disclosure: I don’t know much about PHP at all.)

    Trying to figure this out too. The #2959 bug track indicates that the included patch fixes the problem, but the code seems to be no different from 2.1.2. I can’t figure out what I’d need to change to solve this – can anybody help?

    If your theme uses wp_list_pages, then you have to change a core WP file to fix this temporarily (the bug above describes the design work going into fixing this, but two different things were done which nullified the fix. The milestone is v2.2)

    Anyway – to fix this in the core file (there may be a more efficient/faster way, but it works), edit wp-includes/classes and look for:

    if ( $page->ID == $current_page )

    which is line 512 in v2.1.3 and change it to:

    if ( $page->ID == $current_page or $page->ID == get_settings(‘page_for_posts’))

    Now it should work. But it’ll break the next time you update 🙂 I may spin a plugin with a quick filter fix.

    Er well, no that didn’t work quite right. Grrrr. Sorry about that. Let me try again….

    Well that’s cute. When you are viewing the ‘page for posts’, the page id is set to 0 instead of the true page ID – that’s why things are messed up. But you can’t just check for ‘0’ since there are other times the page ID is 0 (searching, etc)

    So it won’t be perfect, but you COULD try this on line 512:

    if ( $page->ID == $current_page or $page->ID == 0)

    Proper code would check that get_option(‘page_for_posts) > 0, but if you’re making this hack – I’m assuming you knwo you have a static front page.

    If I come up with a decent fix via plugin, I’ll post it

    OK it’s late. That should read:

    if ( $page->ID == $current_page or $current_page == 0)

Viewing 15 replies - 1 through 15 (of 44 total)
  • The topic ‘Problem with “current_page_item” navigation highlighting’ is closed to new replies.