WordPress.org

Ready to get started?Download WordPress

Forums

Special Last Post (2 posts)

  1. blindcanary
    Member
    Posted 5 years ago #

    I'm coding from scratch and was wondering how to make the most recent post have a different layout/set up on the index page then the ones beneath it, sort of like a featured article or headline in a newspaper.

  2. stvwlf
    Member
    Posted 5 years ago #

    One way to do it is to use two loops on the page, add some classes to the featured post display, and style using CSS

    <div class="featured">
       <?php $recent = new WP_Query("cat=1&amp;showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
         <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    	<?php the_content(__('Read the story &raquo;'));?>
       <?php endwhile; ?>
    </div>

    The put a query posts before the main WP loop that skips the most recent post, to avoid duplicating it

    <?php query_posts('offset=1'); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic