WordPress.org

Ready to get started?Download WordPress

Forums

show one post per category within the loop (4 posts)

  1. mikevl
    Member
    Posted 6 years ago #

    Hi there,
    I have been searching for a clean solution for the following:
    On my frontpage I want to show one (the most recent) post per category.
    If I have five categories I would like to list 5 posts (one per category.)

    Can anyone offer advice how to do this in the loop??

  2. MichaelH
    Member
    Posted 6 years ago #

  3. mikevl
    Member
    Posted 6 years ago #

    The link MichaelH supplied doesn't offer the flexibility to 'play' with the layout.

    What I've now done is used the 'loop' below and specified the category id's I wanted to show an article of.
    <?php
    query_posts("cat=15&showposts=1");
    if (have_posts()) : while (have_posts()) : the_post();
    ?>
    <b>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></b>
    <p><?php the_content(''); ?></p>
    <div class="hppostmeta">
    <p><?php the_date('l, F j, Y'); ?> | " rel="bookmark">Read the story ยป</p>
    </div>
    <?php endwhile; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>

    This works fine with just one problem:
    When I use the loop above more than once in my homepage the date is only show correctly the first time..

    any pointers?

  4. moshu
    Member
    Posted 6 years ago #

    The_Loop - see the multiple loops section.

Topic Closed

This topic has been closed to new replies.

About this Topic