• jimmyneutron

    This code hack might be useful to someone. On my web site home page I wanted to show the latest post as a summary and then show the previous 6 posts as simple links.
    You can see how this code works here: https://www.startrekuk.com/.
    This is simply a few if statements wrapped around the content().

    <?php
    $first = True;
    if ($posts) : foreach ($posts as $post) : start_wp(); ?>
    <?php the_date('','<h2>','</h2>'); ?>
    <h3>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></h3>
    <?php if ($first){ ?>
    <?php the_content(); ?>
    <?php } ?>
    <?php $first = False; ?>
    <?php endforeach; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>

Viewing 1 replies (of 1 total)
  • Great stuff. I’ve modified the hack a little bit.
    Now you can choose how many post should be displayed as summary, simply change the $fullposts variable:

    <?php
    $first = 1;
    //number of latest posts which are showed as summary
    //the previous posts will be showed as simple links
    $fullposts = 5;
    if ($posts) : foreach ($posts as $post) : start_wp(); ?>
    <?php the_date('','<h2>','</h2>'); ?>
    <h3>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></h3>
    <?php
    if($first)
    the_content();
    if($first==$fullposts)
    $first = False;
    else
    $first++;
    endforeach; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>

Viewing 1 replies (of 1 total)
  • The topic ‘First post summary for Index.php’ is closed to new replies.