WordPress.org

Support

Support » How-To and Troubleshooting » Displaying complete first post, then truncate the rest.

Displaying complete first post, then truncate the rest.

  • I’ve been searching for an answer, but haven’t quite found one yet.

    I have my posts on the home page truncated, and I’d like to find a way to keep all but the first post truncated. Is there a way to do this?
    <?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,80); ?>
    That’s what I’m currently using to display the excerpts on the home page.

    Thanks for any help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Something similar to this might work:

    <?php
    if (is_front_page() && ++$count == 1) {
       the_content();
    } else {
       $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,80); ?>
    }

    Thanks for the response vtxyzzy. Though, that doesn’t seem to work.

    Any other methods/ideas?

    Thanks!

    <?php
    $count = 0;
    if ($count > 0) {
       $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,80);
    } else {
         the_content();
    }
    $count++;
    ?>

    Use this.

    Hmmm… chinmoy29, this seems close, but it’s displaying the entire post for all posts now…

    With my limited knowledge of PHP, it looks like your code asigns the first post the number 0, and then adds 1 to each following post. Which seems right to me. However, it displays the full post for all items…

    Moderator keesiemeijer

    @keesiemeijer

    Move $count = 0; above of the loop

    Excellent! That got it!

    Thank you guys for all your help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Displaying complete first post, then truncate the rest.’ is closed to new replies.