• boon_

    (@boon_)


    Hey

    I’ve got my sub-navigation set up all follows:

    <?php if($post->post_parent)
    $children = wp_list_pages("title_li=&depth=1&child_of=".$post->post_parent."&echo=0"); else
    $children = wp_list_pages("title_li=&depth=1&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
                	<ul>
    		    <?php echo $children; ?>
    		</ul>
    <?php } ?>

    Which is fine – if I’m on a first or second level page it displays the sub menu showing the second level pages.

    However when I switch to a third level page the menu changes to display only the third level pages. How can I tweak it so it still only shows the second level pages as before?

    Basically I want my navigation to display the second level pages ONLY all the time, even if you go to a third/fourth level page.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Any luck with this, I am using the following code and have the same problem:

    <?php
    	if($post->post_parent)
    	$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    	else
    	$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    	if ($children) { ?>
            <div class="sideblock-pages">
                        <ul class="subpage-list">
                        <?php echo $children; ?>
                        </ul>
            </div>
    <?php } ?>

    Try using the get_post_ancestors in place of post_parent. This approach seemed to work for me:

    <?php
    global $wp_query;
    $post = $wp_query->post;
    $ancestors = get_post_ancestors($post);
    if( empty($post->post_parent) ) {
    	$parent = $post->ID;
    } else {
    	$parent = end($ancestors);
    }
    if(wp_list_pages("title_li=&child_of=$parent&echo=0" )) { ?>
    
    <ul id="secondary-nav">
    	<?php wp_list_pages("title_li=&child_of=$parent&depth=1" ); ?>
    </ul><!-- #secondary-nav -->
    
    <?php } ?>

    Then I used this to target the current nav states with CSS:

    #secondary-nav li a:hover,
    #secondary-nav li.current_page_item a,
    #secondary-nav li.current_page_ancestor a {
    	background:#fcb701;
    }

    I hope this helps!

    Can you get the 4th level using a similar method?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Navigation – 3rd level’ is closed to new replies.