WordPress.org

Ready to get started?Download WordPress

Forums

Creating an Automatic Post Excerpt Display For Front Page (3 posts)

  1. CallUp
    Member
    Posted 4 years ago #

    I would like to set up my Loop to display in full the first three posts, and then for the remainder of the posts (i.e. posts 4, 5, 6, ...) only display the title and a 75 word excerpt from each.

    That way I can just hide the excerpt/more option from the user's add new post functionality and get a consistent front page display.

    Can someone shed some light on how to pull this off.

    I'm guessing I'll need a global count variable to keep track of the number of posts being displayed, but what function would I use? Some variation of content()?

  2. tugbucket
    Member
    Posted 4 years ago #

    // this loop shows #1-3 in full
    
    <?php $posts=query_posts($query_string . '&posts_per_page=3'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php the_content('read more'); ?>
    <?php endwhile; ?>
    <?php else : ?>
    <p>Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>
    
    // this loop then shows #4-6 with only the excerpt
    
    <?php $posts=query_posts($query_string . '&posts_per_page=3&offset=3'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php the_excerpt(); ?>
    <?php endwhile; ?>
    <?php else : ?>
    <p>Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>

    if your familiar with the loop this is not that tough. Changing the length of the excerpt is a little extra though.

    http://jarretcade.net/changing-the-default-wordpress-excerpt-length

  3. ancawonka
    Member
    Posted 4 years ago #

    Thanks Tugbucket, that was very helpful.

    One of the commenters on your page found a simpler solution to setting the excerpt length. Here it is, to save you the click:

    function my_excerpt_length($text){
    return 10;
    }
    add_filter('excerpt_length', 'my_excerpt_length');

    You need to add this to your functions.php file, or wherever you're adding actions and filters.

Topic Closed

This topic has been closed to new replies.

About this Topic