Support » Fixing WordPress » Multiple Loops Problem – Two seperate categories on one page

  • This is driving me nuts! I had it working but then I changed something and I can’t get it to work anymore – I must be missing something really stupid.

    I’ve been searching here for about an hour and I can’t finy any concrete information on this. Here’s my problem:

    I’m trying to have two loops on the index page. The first loop will call the 10 recent posts from “category1” and the second loop will call the 10 recent posts from “category2”.

    You can see my current code here: http://pastebin.com/396261

    I’ve seen a couple so-called solutions to this problem but most involve the first loop only pulling posts “normally” and the second loop pulling the posts as per that link above. This way will not work for me – I need each loop to pull from a seperate category.

    Anyone have any insight on this?
    Thanks

Viewing 1 replies (of 1 total)
  • Try something like the following (Be sure to substitute the category_id’s for the one’s that you’re using):

    query_posts('cat=3');
    if (have_posts()) :
    while (have_posts()) : the_post();
    the_title();
    endwhile;
    endif;
    //now run a new query
    query_posts('cat=5');
    //as $wp_query is reinitialised, let's run the_loop
    if (have_posts()) :
    while (have_posts()) : the_post();
    the_title();
    endwhile;
    endif;

    This is a minor modification of the technique described in this article.

Viewing 1 replies (of 1 total)
  • The topic ‘Multiple Loops Problem – Two seperate categories on one page’ is closed to new replies.