Highlighting the current page in a navigation menu which links are generated with a custom loop?

This is a second navigation menu I’m using:

    <ul id="forums">
        <?php $custom_posts = new WP_Query(); ?>
        <?php $custom_posts->query('post_type=bbp_forum'); ?>
        <?php while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?>
            <li><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></li>
        <?php endwhile; ?>
    </div><!-- #access -->

Is a custom loop which list a custom post type called Forum.

Read More

I would like to highlight the current Forum link, like this:

enter image description here

Any suggestions?

Related posts

Leave a Reply

1 comment

  1. So, if I understand correctly, when you’re on a single post page, you want to have a navigation menu with all the posts of post_type bbp_forum.

    I had a similar case (without the post_type, but it’s not a problem to add it), and I used code that I found that talked about posts of same category, on single post pages.

    The code goes as follows (with customization for post_type):

    <ul>  
      <?php global $post; $cat_posts = get_posts('post_type=bbp_forum');
      foreach($cat_posts as $post) : ?>  
        <li <?php if($post->ID == get_the_ID()){ ?>class="cur_post" <?php } ?>>
            <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) );  rel="bookmark"?>" ><?php the_title(); ?></a>
         </li>
      <?php endforeach; ?>
    </ul>
    

    I hope that’s what you meant.

    P.S – I also see that you have an opening <ul> tag, but a closing <div> tag….