Support » Fixing WordPress » Using multiple loops and displaying them chronologically

  • Hi all. Stop me if this is too complex but I cannot for the life of me figure this out.

    I have a home page that has 4 loops, each displaying the most recent post for a category. For example, there is a loop for cat 1, another loop for cat 2, etc. However, what I want to do is display the most recent post from each category chronologically instead of being in static places. I feel like there is an easier way than using multiple loops, nor can I figure it out using multiple loops. Any guidance?

Viewing 7 replies - 1 through 7 (of 7 total)
  • For the main loop, you use query_posts
    http://codex.wordpress.org/Function_Reference/query_posts

    For secondary loops, use get_posts
    http://codex.wordpress.org/Template_Tags/get_posts

    Read through the documentation. You should find what you’re looking for.

    Peter_L, I think you got it. I’m playing with the new code now.

    No, that’s wrong. You can call all the different category names in one query_posts and then use different query_posts parameters to do what you want. Read through this:
    http://codex.wordpress.org/Function_Reference/query_posts

    Sorry, I think we are posting at the same time. After you sent your links, it was the insight that I needed. I wanted to get rid of that embarrassing code before anyone else saw it.

    <?php
        $args=array(
          'category__in' => array(1,2,3,4),
          'posts_per_page' => 4,
          'orderby' => 'post_date',
          'order' => 'DESC'
         );
         $wp_query->query($args);
      ?>

    I have this, but here is where I am lost. Is it possible to show 1 post from each category, and whichever post is the most recent has to be at top? For instance, only one post is shown for category 1,2,3,4. But category 2 has the most recent post and needs to be at the top. I’m wondering if it’s even possible doing it this way.

    It might be possible this way but I don’t think so.

    What you can do is use above code and put ‘numberposts’ to 1. That would give you the most recent post.

    Then try and get the category that most is in and save it in a variable. Next you run 3 get_posts and you use above id as a negative.

    Thank you for your help. I decided to do things a different way and restructure the design. The solution I came up with is easier and makes more sense.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Using multiple loops and displaying them chronologically’ is closed to new replies.