WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. bcreighton
    Member
    Posted 6 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") {
    
    if($post->post_parent)
    $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) { ?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } } ?>
    
    </li>

    Thanks

  2. bcreighton
    Member
    Posted 6 years ago #

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

  3. zoblue
    Member
    Posted 6 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 PAGE NAVIGATION
    [* home] [archives] [about] [stats] [contact]

    ABOUT PAGE NAVIGATION
    [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:
    http://blog.zoblue.com/

    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