• Hello. I have a problem with my menu, and if you could help me I would be very happy!

    I want the current page in my navigation to be highlighted. It works for all pages except my “posts” page, which is my blog page. Here is the code I am using in my header template:

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

    It works fine for every page except the blog page which is my “posts page.” The problem I am having is when you navigate to the the blog page (where the posts are) it isn’t getting recognized as a “current page.”

    Please help me!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Highlight Current Page in menu not working on "posts" page’ is closed to new replies.