Support » Plugins » modification to wp_list_pages: current_page_item

  • 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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • heh. come on you guys! I believe in you. 😉


    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.

    This is the plugin I use:

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘modification to wp_list_pages: current_page_item’ is closed to new replies.