WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Full article for first post excerpts for the rest? (7 posts)

  1. Wealthed
    Member
    Posted 3 years ago #

    Hi I am using the Therapy theme, I would like the newest post to display in full on the homepage but every post after that I would like to display only the excerpt I searched the forums and found that I could replace my the_content area with <?php if (!i) the_content(); else the_excerpt(); i=1; ?> to accomplish this but that gave me an error. Here is what the current the_content section looks like in my themes index.php:

    <?php if ( get_option('woo_content_home') == "true" )
    the_content('[...]'); else the_excerpt(); ?>

    Thanks in advance!

  2. Tara
    Member
    Posted 3 years ago #

    A new pugin called "Ultimate Post Type Manager" came out today. See if it can do what you want

  3. Wealthed
    Member
    Posted 3 years ago #

    Not really looking for a plugin here since I'm already using a plugin to allow my excerpts to contain html writeup, just looking for a very simple one line modification in index.php to make it so that only the excerpt is shown on all the posts except for the very newest one.

    Thanks for the reply though!

  4. Digital Raindrops
    Member
    Posted 3 years ago #

    Just add a counter inside the loop, this could be in index.php or loop.php, not one line but not to many!

    <?php while ( have_posts() ) : the_post(); ?>
    <?php /* Increment the Counter */ ?>
    <?php $counter++; ?>

    Then in the content div where you will find the_content()

    <?php /* Conditional Output */ ?>
    <?php if($counter==1 : ?>
       <?php the_content(); ?>
    <?php else: ?>
      <?php the_excerpt(); ?>
    <?php endif; ?>

    HTH

    David

  5. Wealthed
    Member
    Posted 3 years ago #

    Thank you David!!!

    I was getting an error at first when I replaced the_content then I just added this line

    <?php $counter++; ?>

    under <?php endif; ?>

    and now it is working perfectly, thank you so much!

  6. Digital Raindrops
    Member
    Posted 3 years ago #

    Hi,
    Great, could you mark this as resolved please.

    For reference and anyone else that might find this topic in a search.
    I can see the error in my code, missing paranthasis.

    <?php if($counter==1 : ?>
    Should be
    <?php if($counter==1) : ?>

    This would still work with the $counter just inside the loop, if you add it after the endif, it would not be set until after the first loop, so it would be false (zero) in the first loop and the second would be '1'.

    The original code was adapted from code I have to add striped post titles, and it could be changed to make it easier.

    <?php /* Conditional output flag set after first post */ ?>
    <?php if($showexcerpt) : ?>
       <?php the_excerpt(); ?>
    <?php else: ?>
      <?php the_content(); ?>
    <?php endif; ?>
    <?php $showexcerpt=true; ?>

    HTH

    David

  7. stacydolderer
    Member
    Posted 3 years ago #

    Thank you! This worked great.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.