WordPress.org

Ready to get started?Download WordPress

Forums

modification to wp_list_pages: current_page_item (4 posts)

  1. ericmcgregor
    Member
    Posted 7 years ago #

    Hi folks,

    I'm so close! I have a navigation menu based on wp_list_pages(). When I click on a child page, I want the 'current_page_item' class to REMAIN on the PARENT.

    I am re-writing wp_list_pages and _page_level_out in the template-functions-post.php

    The bit of code I need to modify is under _page_level_out() and it reads:

    foreach ( $page_tree[$parent]['children'] as $page_id ) {
    $cur_page = $page_tree[$page_id];
    $title = $cur_page['title'];

    $css_class = 'page_item';
    if ( $page_id == $queried_obj->ID )
    $css_class .= ' current_page_item';

    Basically I need to modify this to say: If this is the queried object, and it's the child of a parent page, then add the current_page_item to the parent.

    I hope that makes sense. I've made a little progress, but I'm not a great coder. Your help is really appreciated.

  2. ericmcgregor
    Member
    Posted 7 years ago #

    heh. come on you guys! I believe in you. ;)

  3. kilbot
    Member
    Posted 7 years ago #

    Hi,

    Add $page_id == $queried_obj->post_parent to the If statement. ie:

    if ( $page_id == $queried_obj->ID || $page_id == $queried_obj->post_parent )

    That should do the trick, but someone may suggest a plugin method which is obviously better than editing the wordpress core files.

  4. Ryan Fitzer
    Member
    Posted 7 years ago #

    This is the plugin I use:

    http://www.webspaceworks.com/resources/cat/wp-plugins/30/

    It allows a class of "current_page_ancestor" to be apllied to a child page's parent's <li> element. It keeps the "current_page_item" class applied to the child's <li> element. This way I can style my main nav and sub-nav separately.

Topic Closed

This topic has been closed to new replies.

About this Topic