Support » Plugins » Hacks » Menu with Child Pages

  • Linosa


    I’ve used a hack I found here at the forum for my menu. It works perfectly except for two things.

    1. I would like the second level (sub-menu) to sort by ID and not alphabetically.
    2. The third level on the menu is now included in the second level. I don’t want the third to be displayed at all.

    Any ideas? Here’s my code.

    	$pages = get_pages( array(
    		    	'sort_order' => 'ASC',
    		    	'sort_column' => 'menu_order',
    		    	'parent' => 0 )
    		if ($post->post_parent)
    			//I am a subpage
    			$id = $post->post_parent;
    			//I am a page
    			$id = $post->ID;
    		$subpages = get_pages(array("child_of"=>$id));
    <ul id="navcatlist">
    <?php foreach ($pages as $page):?>
    	<li <?php if ( ($page->ID == $post->ID) || ($post->post_parent == $page->ID) ) echo 'class="current-page-item"'?>>
    		<a href="<?php echo get_permalink($page->ID); ?>"><?php echo $page->post_title ?></a>
    		if ( ($page->ID == $post->ID) || ($post->post_parent == $page->ID) ):	
    				foreach($subpages as $subpage):
    			<li <?php if ($subpage->ID == $post->ID) echo 'class="current-subpage-item"'?>>
    				<a href="<?php echo get_permalink($subpage->ID); ?>"><?php echo $subpage->post_title ?></a>
    			<?php endforeach; ?>
    		<?php endif; ?>
    <?php endforeach;?>
  • The topic ‘Menu with Child Pages’ is closed to new replies.