• Hi,

    I have my most recent posts listed in my sidebar and am trying to figure out dynamic menu highlighting for the post when selected. My sidebar code looks like this:

    <h2>WORK</h2>
    <?php query_posts(‘category=work&showposts=15’); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    <div id=”post-<?php the_ID(); ?>”>

    <h3>“><?php the_title(); ?></h3>

    <?php endwhile; ?>

    <?php else : ?>

    <?php endif; ?>
    </div>

    I would like to put a conditional tag on the h3 tag of my post so that if we are viewing the post is becomes <h3 class=”current”>. I imagine it would be something like <h3 <?php if…class=\”current\””>> but I can’t figure out the conditional tag. I feel it may be a problem because the actual post it in another loop. Has anyone any experience with something like this?

    Thank you for any help, it is very much appreciated.

    Nick

Viewing 2 replies - 1 through 2 (of 2 total)
  • when the sidebar code is called after the main column loop, you could try to save the post id of the center column in a variable, and check this in your if statement:

    <?php $main_post_id = $post->ID; ?>
    
    <h2>WORK</h2>
    <?php query_posts('category=work&showposts=15'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    
    <div id="post-<?php the_ID(); ?>">
    
    <h3 <?php if( get_the_ID() == $main_post_id ) { echo ' class="current"'; } ; ?>><a href="...."><?php the_title(); ?></a></h3>
    
    <?php endwhile; ?>
    
    <?php else : ?>
    
    <?php endif; ?>
    </div>

    and in style.css:
    h3.current a { color:#123456; }

    Thread Starter nickbudden

    (@nickbudden)

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘a conditional statement for the post id?’ is closed to new replies.