How do I add a current class to the current post?

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="https://wordpress.stackexchange.com/questions/26841/<?php the_permalink(); ?>"><?php the_title(); ?><br /><span><?php the_author(); ?></span></a>
                </li>   
    <?php endforeach; ?>
</ul>

Leave a Comment