Support » Fixing WordPress » Style current Page differently for wp_list_pages?

  • Resolved bcreighton


    Hi, I am using the following code to create subnav for the current Page. My client would like the Page the user is currently on to be styled a different color. Does anyone know of a way to modify wp_list_pages so that it doesn’t link the current page or adds a class to the link?

    <li><a href="/index.php?page_id=9">Who</a>
    <!--check for Who (ID = 9) subpages-->
    <?php if (is_page(9) || $post->post_parent=="9") {
    $children = wp_list_pages("sort_column=post_date&title_li=&child_of=".$post->post_parent."&echo=0"); else
    $children = wp_list_pages("sort_column=post_date&title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <?php echo $children; ?>
    <?php } } ?>


Viewing 2 replies - 1 through 2 (of 2 total)
  • ooops, WP already creates a class for the current page 🙂 I love WP 😀

    This is what I want to do as well, however, I want to go a step further! It’s a challenge…

    I’m using background images for each item in the wp_list_pages so each item is different. For example, each link is a button with white text but when you are on a particular page I want the link to become blue text with an icon next to it, like so….

    [* home] [archives] [about] [stats] [contact]

    [home] [archives] [*about] [stats] [contact]

    I cannot achieve this using wp_list_pages because the class “current_page_item” has to be different for each item in the list. Right now, the home button is “active” on every page on my blog because it’s hard-coded that way in header.php and can’t be coded differently for each page.

    My second question is how do I add the home page as a ‘page’ so it shows up in the wp_list_pages with the styles added accordingly.

    Please let me know if I’m not making sense! You can check my blog if you’d like to see how I have hard-coded the navigation:

    I’m thinking this is going to involve some kind of PHP-read-the-url-and-auto-magically-add-the-style-needed. I just don’t have the advanced know-how. 😀

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Style current Page differently for wp_list_pages?’ is closed to new replies.