Menu with Child Pages (1 post)

  1. Linosa
    Posted 5 years ago #

    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;?>

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.