• Resolved dcbaldwin1

    (@cousti)


    Hello. My name is Derek and I have been struggling for hours with this problem. Anyone that can help I greatly appreciate it.

    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: (I have also used plugins which I talk about below the code.

    <div id="mainnav">
    <ul id="mainnav">
    
            <li<?php
                    if (is_home())
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a href="<?php bloginfo('url') ?>">Home</a>
            </li>
              <li<?php
                    if (is_page('about'))
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a href="<?php bloginfo('url') ?>/about">About</a>
            </li>
              <li<?php
                    if (is_page('lessons'))
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a href="<?php bloginfo('url') ?>/lessons">Lesson Pricing</a>
            </li>
              <li<?php
                    if (is_page('student-gallery'))
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a href="<?php bloginfo('url') ?>/student-gallery">Student Gallery</a>
            </li>
               <li<?php
                    if (is_page('blog'))
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a href="<?php bloginfo('url') ?>/blog">Blog</a>
            </li>
               <li<?php
                    if (is_page('contact'))
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a href="<?php bloginfo('url') ?>/contact">Contact</a>
            </li>
    </ul></div>

    It works fine for every page except the blog page which is my “posts page.” I have tried using the plugins Menu Maker and WP Menu Manager and get the exact same result. 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.” I have checked this with Firebug. FYI, I am not having problems with the CSS, as every page but my blog page (posts page) is highlighted when current.

    I also have a similar problem with breadcrumbs. Everything comes up on the breadcrumbs except the blog page, which is the posts page. When I navigate to the blog page, the breadcrumbs indicate I am on the home page.

    I am absolutely stumped. Again, your help is greatly appreciated.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Don’t know if this is the issue, but according to Conditional_Tags:

    is_home()
    When the main blog page is being displayed. (WordPress 2.1 handles this function differently than prior versions. See Alternate Methods for Setting the Front Page for pre-2.1 WP.)

    Note: If you select a static Page as your frontpage (see below), this tag will be applied to your “posts page”.

    is_front_page()
    When it is the front of the site displayed, whether it is posts or a Page. Returns true when the main blog page is being displayed and the ‘Settings > Reading ->Front page displays’ is set to “Your latest posts”, or when ‘Settings > Reading ->Front page displays’ is set to “A static page” and the “Front Page” value is the current Page being displayed. Note: this tag was added at Version 2.5.

    Thread Starter dcbaldwin1

    (@cousti)

    🙂 !!!! Fixed it! Thank you for your help!

    The code now is:

    <ul>
    <li<?php
                    if (is_front_page())
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a href="<?php bloginfo('url') ?>">Home</a>
            </li>
              <li<?php
                    if (is_page('about'))
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a href="<?php bloginfo('url') ?>/about">About</a>
            </li>
              <li<?php
                    if (is_page('lessons'))
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a href="<?php bloginfo('url') ?>/lessons">Lesson Pricing</a>
            </li>
              <li<?php
                    if (is_page('student-gallery'))
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a href="<?php bloginfo('url') ?>/student-gallery">Student Gallery</a>
            </li>
               <li<?php
                    if (is_home())
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a href="<?php bloginfo('url') ?>/blog">Blog</a>
            </li>
               <li<?php
                    if (is_page('contact'))
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a href="<?php bloginfo('url') ?>/contact">Contact</a>
            </li>
    
    </ul>

    Thanks again!

    dbcuadro

    (@dbcuadro)

    Hi everyone,

    What if the wordpress address (www.example.com/blog) and blog address (www.example.com) are different? How can I link to the blog posts using the example above?

    The reason I’m having an issue is because my front page is set to display a static page (index). Essentially I want my menu to work exactly the same as above.

    stoarcecreierul

    (@stoarcecreierul)

    Is somebody around here who knows how the css for the highlited item would look like?

    I don’t mean the actual attributes, only how they are declared.

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

    @linosa

    your code seems to assign the css class .current-page-item and .current-subpage-item resp.

    do you have corresponding styles in style.css?

    for instance:

    .current-page-item a { ... }
    .current-subpage-item a { ... }

    so what is not working?

    a link to your site might help to illustrate your problem.

    It’s all done correctly in my css-file.

    The problem is that my subpages and the “current highlighting” dosen’t work at my “Latest news” page, which is a page with posts. It works fine for all content pages.

    Here’s a link to my site:
    http://ateensonline.com/

    The news can be found at “What’s up”.

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