WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Sub-menu issue (2 posts)

  1. Webb7
    Member
    Posted 10 months ago #

    I got my menu (left side) to display the relevant submenu when the parent was click on. But when you click onto that sub menu, the rest disappears.

    Website

    When clicked on the parent page it will list the sub pages below but when I click onto one of those sub pages, then they will no longer be there.

    Here is the coding which I'm using:

    <?php
    if(!$post->post_parent){
    	// will display the subpages of this top level page
    	$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    }else{
    	// diplays only the subpages of parent level
    	//$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    
    	if($post->ancestors)
    	{
    		// now you can get the the top ID of this page
    		// wp is putting the ids DESC, thats why the top level ID is the last one
    		$ancestors = end($post->ancestors);
    		$children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");
    		// you will always get the whole subpages list
    	}
    }
    
    if ($children) { ?>
    	<ul>
    		<?php echo $children; ?>
    	</ul>
    <?php } ?>

    For my CSS:

    .page_item .children {
      display: none;
    }
    
    .current_page_item .children {
      display: block;
    }

    Anyone know how I can get it successfully work so that when I'm on the sub page it will display the sub pages under that parent.

  2. Webb7
    Member
    Posted 10 months ago #

    Solved by adding this to my CSS instead

    ul.children {display: none;}
    .current_page_item ul.children,
    .current_page_parent ul.children {display: block;}

Reply

You must log in to post.

About this Topic