Support » Your WordPress » 6 loops on the home page

  • I want to have 6 loops on my home page, each displaying a different category. I cannot use query_posts cuz it can only be used once and on the main loop and the explanation on wp_query is not enough for me. would some one give me a better explanation that the one in the codex? I’d really appreciate that 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’ve been using WP_query fairly extensively the last while and while I found the Codex explanation a little confusing at first, it does actually make sense.

    Here’s an example of a usage I’ve made of WP_query

    // Assign your "new" WP_query to a variable
    $newReleases = new WP_query();
    // Define a query that this variable is going to act on your new WP_query - in this case I'm asking for it to show 5 posts ordered by day in any of categories 1, 2, or 3.
    $newReleases->query(array('showposts' => 5, 'orderby' => "date", 'category__in' => array(1,2,3)));
    // That's our new query set up, now we can act on this with a (nearly) standard WP loop.
    // Instantiate the loop but using our predefined WP_query
    <?php while ($newReleases->have_posts()) : $newReleases->the_post(); ?>
    // Depending on your needs do some stuff as per normal loop :)
    <h3 class="post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
    <?php the_excerpt(); ?>
    <?php endwhile; ?>

    Hope that makes sense?

    Thank you, I think thats gonna help…but i gotta try 🙂

    I just read that code from alexleonard above. That is helpful the way you’ve got it commented. Thanks. Good thread so far.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘6 loops on the home page’ is closed to new replies.