6 loops on the home page (4 posts)

  1. TheUniQueBoY
    Posted 7 years ago #

    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 :)

  2. alexleonard
    Posted 7 years ago #

    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?

  3. TheUniQueBoY
    Posted 7 years ago #

    Thank you, I think thats gonna help...but i gotta try :)

  4. Dgold
    Posted 7 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic