WordPress.org

Ready to get started?Download WordPress

Forums

Showing one full article and then excerpts (5 posts)

  1. Mark Bloomfield
    Member
    Posted 8 years ago #

    Hey guys...

    I'd like to have my blog show the first/most recent article in full and then the remaining posts to be excerpts...

    So forexample, if I've set my blog to show 20 articles on the front page, then it'll show 1 full article and then the balance, 19, in excerpts...

    Something like what has been done on this blog: http://www.localvocal.co.za

    I hope you guys can help...

    Regards

  2. Kafkaesqui

    Posted 8 years ago #

    Simplest method would be to add a PHP variable into The Loop which increments for each post, like this:

    <?php
    if(have_posts()) : while(have_posts()) : the_post();
    $postcount++;
    ?>

    Then alter the the_content() tag code to test on it, like this:

    <?php
    if($postcount > 1) {
    the_excerpt();
    } else {
    the_content();
    }
    ?>

  3. OnSeduction
    Member
    Posted 8 years ago #

    You could add a post counter into the loop. Eg: before the loop you set $i=0 and in the loop $i++. Then depending on the value of $i (in your case when $=1) do something with it.

    edit: like kafkaeski said faster

  4. Mark Bloomfield
    Member
    Posted 8 years ago #

    awesome guys, thanks very much.. i'll test it out when i get to coding... just wanted 2 make sure it can be done...

    one thing to throw in the mix...

    i want to have 2 loops... basically, if you can imagine... a left panel with a full article in it and then a second div as a right panel with the remaining excerpts/article titles in it... i'd need to loops running right?

    is the above possible with this format?

  5. Kafkaesqui

    Posted 8 years ago #

    Thought I'd add that you can also use the $posts object as a counter of sorts. For that there's no need for a "count" var; just change the_content() to:

    <?php
    if($post == $posts[0]) {
    the_content();
    } else {
    echo the_excerpt();
    }
    ?>

    ...

    EDIT:
    Missed you're followup with this reply. For a second loop, look at get_posts(). It provides an offset argument which would let you pass over the first (latest) post from your initial loop. Note the information there on setting up a custom loop for processing the posts.

Topic Closed

This topic has been closed to new replies.

About this Topic