[resolved] Style current Page differently for wp_list_pages? (3 posts)

  1. bcreighton
    Posted 8 years ago #

    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 } } ?>


  2. bcreighton
    Posted 8 years ago #

    ooops, WP already creates a class for the current page :) I love WP :D

  3. zoblue
    Posted 8 years ago #

    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. :D

Topic Closed

This topic has been closed to new replies.

About this Topic