• Yah, I know, odd, huh? I’m not much of a PHP geek, I do nothing but copy and paste. I’ve got something here that peaked my curiosity.
    So, OK, here goes…

    I just found this and put it in my header.php for the navigation:

    <ul class="navigation">
    <li class="first <?php if ( is_home() ) { ?>current_page_item<?php } ?>"></li>
    <?php wp_list_pages('sort_column=menu_order&depth=1&title_li=');?>
    </ul>

    I added in that 2nd PHP string, which makes the current page’s link color change, by giving it the “.current_page_item” class, so it can be styled it in the CSS.

    BUT…, I am using a custom template for my landing (Home) page which I’ve set to call a DIFFERENT header (homeheader.php) which only has THIS for the navigation:
    <ul class="navigation"><?php wp_list_pages('depth=1&title_li='); ?></ul></div>
    Nothing about “.current_page_item” in there.

    So why does it work across the whole site, by giving the current page in the nav the “.current_page_item” class?

    Site: https://www.defossesdesign.com/blog

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter geezerd

    (@geezerd)

    Sorry, I mean I added in that FIRST PHP string.
    <li class="first <?php if ( is_home() ) { ?>current_page_item<?php } ?>"></li>

    Thread Starter geezerd

    (@geezerd)

    And now that I look closer at my custom headers, it’s not the same as that in the navigation at all, it’s this:

    <ul class="navigation">
    <?php wp_list_pages('depth=1&title_li='); ?>
    </ul>

    wp_list_pages adds the class current_page_item automatically.

    The one exception would be the blog’s page if the blog is currently set to show the latest posts (ie it’s a Posts page rather than a Page page).

    Thread Starter geezerd

    (@geezerd)

    Ah, OK, so it wasn’t adding that that did it, it was creating the CSS to change the color?

    I just never noticed that “current_page_item” class was already there?

    Thread Starter geezerd

    (@geezerd)

    I see, it was! Mystery solved, hahah.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Can anyone tell me why this IS working?’ is closed to new replies.