Forums

excerpt only for the last post (3 posts)

  1. Vitalfi
    Member
    Posted 1 year ago #

    Hi,
    I ask your help to change my theme. I would like to change the archive pages to view the excerpt only for the last post. For the other ones I just want the title with the link.
    Is it possibile to do something like this?
    Thank so muck

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    edit archive.php;

    the rest depends on the theme that you are using, as the code in the templates files can vary.

    it can be done using a counter variable in the loop, to show the excerpt only once if the counter is equal to 1;

    example code from the (before wp3) kubrick default theme:

    <?php $counter = 1;
    while (have_posts()) : the_post(); ?>
    <div <?php post_class() ?>>
      <h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
        <?php if( $counter == 1 ) { //only show excerpt once
    	<div class="entry">
    	<?php the_excerpt(); ?>
    	</div>
        <?php $counter++; } // increase counter ?>
    </div>
    <?php endwhile; ?>

    if you need more help, please post the name and download link of your theme, and maybe a link to your site.

  3. Vitalfi
    Member
    Posted 1 year ago #

    Hi,
    thank you for your help.
    I changed the theme. The result is here:
    http://www.grandchelem.it

    Bye

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags