WordPress.org

Ready to get started?Download WordPress

Forums

Displaying complete first post, then truncate the rest. (7 posts)

  1. dustinw
    Member
    Posted 3 years ago #

    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!

  2. vtxyzzy
    Member
    Posted 3 years ago #

    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); ?>
    }
  3. dustinw
    Member
    Posted 3 years ago #

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

    Any other methods/ideas?

    Thanks!

  4. chinmoy
    Member
    Posted 3 years ago #

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

    Use this.

  5. dustinw
    Member
    Posted 3 years ago #

    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...

  6. keesiemeijer
    moderator
    Posted 3 years ago #

    Move $count = 0; above of the loop

  7. dustinw
    Member
    Posted 3 years ago #

    Excellent! That got it!

    Thank you guys for all your help!

Topic Closed

This topic has been closed to new replies.

About this Topic