WordPress.org

Ready to get started?Download WordPress

Forums

6 loops on the home page (4 posts)

  1. TheUniQueBoY
    Member
    Posted 5 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 :)
    THANKS

  2. alexleonard
    Member
    Posted 5 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

    <?php
    // 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.
    
    ?>
    <h2>Heading</h2>
    
    // 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 :)
    <div>
    <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(); ?>
    </div>
    <?php endwhile; ?>

    Hope that makes sense?

  3. TheUniQueBoY
    Member
    Posted 5 years ago #

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

  4. Dgold
    Member
    Posted 5 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

Tags