Quantcast
Channel: WordPress › Support » Tag: how to - Recent Posts
Viewing all articles
Browse latest Browse all 30

Linosa on "Highlight Current Page in menu not working on "posts" page"

$
0
0

I have the same problem. This is my menu code:

<?php
	$pages = get_pages( array(
		    	'sort_order' => 'ASC',
		    	'sort_column' => 'menu_order',
		    	'parent' => 0 )
				);
	?>
	<?php
		if ($post->post_parent)
			//I am a subpage
			$id = $post->post_parent;
		else
			//I am a page
			$id = $post->ID;

			$subpages = get_pages("child_of=".$id."&sort_column=menu_order&&exclude=1355,1352,1358,1360,1362,1342,1364,1367");

	?>
<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>
		<?php
		if ( ($page->ID == $post->ID) || ($post->post_parent == $page->ID) ):	

		?>
		<ul>
			<?php
				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>
			</li>
			<?php endforeach; ?>
		</ul>
		<?php endif; ?>
	</li>

<?php endforeach;?>

Viewing all articles
Browse latest Browse all 30

Trending Articles