Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this list set up of the latest 7 posts:

            <ul id="post-list">
            <?php
            global $post;
            $args = array( 'numberposts' => 7 );
            $myposts = get_posts( $args );
            foreach( $myposts as $post ) :  setup_postdata($post); ?>
                <li>
                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?><br /><span><?php the_author(); ?></span></a>
                </li>
            <?php endforeach; ?>
            </ul>

How can I have a class of 'current' be displayed for the current post?

share|improve this question
1  
Does the solution in this question work? –  Devin Humbert Aug 25 '11 at 4:06
add comment

1 Answer 1

try this:

<ul id="post-list">
    <?php
        global $post,$wp_query;
    $current_id = $wp_query->get_queried_object_id();
    $args = array( 'numberposts' => 7 );
    $myposts = get_posts( $args );
        foreach( $myposts as $post ) :  setup_postdata($post); ?>
            <li<?php if ($current_id == $post->ID) echo ' class="current"'; ?>>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?><br /><span><?php the_author(); ?></span></a>
                </li>   
    <?php endforeach; ?>
</ul>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.