WordPress.org

Ready to get started?Download WordPress

Forums

highlighting parent of current_page_parent in 4-level menu list (2 posts)

  1. heriz
    Member
    Posted 6 years ago #

    Hello hello.

    Had a good thorough search in the Codex and on Google for a solution to this, but not seen a squeak on it.

    Is there a technique to make the PARENT of the CURRENT PAGE'S PARENT highlighted in a 4-level page menu? I'm talking grand-parents and great-grand-parents. I want the page item to hover red before being selected, stay red when selected, and stay red when its child and child's child are selected.

    Currently I have my css in this format (it is very unwieldy, and I've stripped out the non-relevant code):

    /*sidebar list level1 */
    #sidebar ul {}
    #sidebar ul li {}

    /*sidebar list level2 */
    #sidebar ul li ul {}
    #sidebar ul li ul li {}

    #sidebar ul li ul li.current_page_item a, #sidebar ul li ul li.current_page_parent a {
    color:red
    }

    /*sidebar list level3 */
    #sidebar ul li ul li ul {}
    #sidebar ul li ul li ul li.page_item a {}

    #sidebar ul li ul li ul li.page_item a:hover, #sidebar ul li ul li ul li.current_page_item a, #sidebar ul li ul li ul li.current_page_parent a {
    color:red
    }

    /*sidebar list level4 */
    #sidebar ul li ul li ul li ul {}
    #sidebar ul li ul li ul li ul li.page_item a {}

    #sidebar ul li ul li ul li ul li.page_item a:hover, #sidebar ul li ul li ul li ul li.current_page_item a, #sidebar ul li ul li ul li ul li.current_page_parent_parent a {
    color:red
    }

    --

    The highlighting of current page parents works for two levels, but not three or four. I've tried many permutations of current_page_parent, page_parent etc, but none of it reaches back far enough.

    The html/php is:

    <?php
    global $notfound;
    if (is_page() and ($notfound != '1')) {
    $current_page = $post->ID;
    while($current_page) {
    $page_query = $wpdb->get_row("SELECT ID, post_title, post_status, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
    $current_page = $page_query->post_parent;
    }
    $parent_id = $page_query->ID;
    $parent_title = $page_query->post_title;

    // if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_status != 'attachment'")) {
    if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_type != 'attachment'")) {
    ?>

  2. <h4 class="sidebartitle"><?php _e('PAGES MENU/LIST'); ?></h4>
    <ul class="list-page">
    <?php wp_list_pages('sort_column=menu_order&title_li=&child_of='. $parent_id); ?>

  3. <?php comments_template(); ?>
    <?php } } ?>

    Any ideas, anyone?

  • heriz
    Member
    Posted 6 years ago #

    Still no dice on this one.

    No-one needed to do this?

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags