WordPress.org

Support

Support » How-To and Troubleshooting » Child listing including parent and current page class

Child listing including parent and current page class

  • I found many posts explaining how to list child pages and also include the parent. However, I bumped into the problem that the parent wasn’t recognized as the current page. Therefore, when styling the page listing to display the current page different from the other (child) pages, it didn’t work when on the parent page.

    Ultimately, I found the following solution and I thought it might be useful to share over here.

    What the code does is three things:
    1) list the parent as well as the children on both the parent page and the child pages;
    2) give the parent page the ‘page_item’-class and, being the first listed, a seperate ‘first-item’-class (useful for styling);
    3) give the parent page the ‘current_page_item’-class when on the parent page (the children get this class automatically from the ‘wp_list_pages’ function).

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    The main part of this code I found in another post, however I haven’t been able to find it again, so I cannot link there to give the credits to the right person.

  • The topic ‘Child listing including parent and current page class’ is closed to new replies.
Skip to toolbar