• Loops are normally arranged by time, but I would like to arrange them by time and category. All posts from category Fruits would be listed first and from category Vegetables second…

    See the wicked illustration below

    LOOP STARTS

    POST1 FROM CATEGORY FRUIT
    POST2 FROM CATEGORY FRUIT

    POST3 FROM CATEGORY VEGETABLES
    POST4 FROM CATEGORY VEGETABLES

    POST5 FROM CATEGORY UNCATEGORIZED
    POST6 FROM CATEGORY UNCATEGORIZED

    I can of course do this by building three loops, but I think there’s a lighter way to do this, or is there?

    // Loop 1
    <?php query_posts('cat=1&showposts=2'); ?>
    <?php $posts = get_posts('category=1&numberposts=2&offset=0');
    foreach ($posts as $post) : start_wp(); ?>
    	<div class="post">
    		...
    	</div>
    <?php endforeach; ?>
    
    // Loop 2
    <?php query_posts('cat=2&showposts=2'); ?>
    <?php $posts = get_posts('category=2&numberposts=2&offset=0');
    foreach ($posts as $post) : start_wp(); ?>
    	<div class="post">
    		...
    	</div>
    <?php endforeach; ?>
    
    // Loop 3
    <?php query_posts('cat=3&showposts=2'); ?>
    <?php $posts = get_posts('category=3&numberposts=2&offset=0');
    foreach ($posts as $post) : start_wp(); ?>
    	<div class="post">
    		...
    	</div>
    <?php endforeach; ?>

    All help is appreciated ?? Cheers.

  • The topic ‘Posts in loop ordered by category?’ is closed to new replies.