Forums

Multiple loops showing one category. (18 posts)

  1. Melee VIII
    Member
    Posted 2 years ago #

    I am trying to make a page with multiple loops and each loop showing one specific category. I have seen various ways to make multiple loops but only some work. And I can't seem to find a way to show only the posts of one category in a loop.

    Thanks in advance.

  2. songdogtech
    Member
    Posted 2 years ago #

    This shows the title and permalink of the latest post in mycategory. Change showposts to -1 to show all posts, or another number to show that number of posts. This loop can be used mutliple times in page; the key is the new query:

    <?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?><?php while ($my_query->have_posts()) : $my_query->the_post(); ?><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a><?php endwhile; ?>

  3. Melee VIII
    Member
    Posted 2 years ago #

    It doesn't show any posts at all.

  4. songdogtech
    Member
    Posted 2 years ago #

    Are you using that loop on a page or page template in a post?

  5. Melee VIII
    Member
    Posted 2 years ago #

    On the index.

  6. songdogtech
    Member
    Posted 2 years ago #

    In index.php? Post your index.php at WordPress Pastebin and then put the link here.

  7. Melee VIII
    Member
    Posted 2 years ago #

  8. songdogtech
    Member
    Posted 2 years ago #

    See pastebin; it's better to modify the existing WP loop than run a new query.

  9. Melee VIII
    Member
    Posted 2 years ago #

    But if I want to add a new one?

  10. songdogtech
    Member
    Posted 2 years ago #

    Use the pastebin code for your first query. Then put the new query (that's in my first post above) after <?php }; ?> and before the <?php endwhile; ?>

  11. Melee VIII
    Member
    Posted 2 years ago #

    Ok, thank you.

  12. Melee VIII
    Member
    Posted 2 years ago #

    The new query doesn't show anything at all...

  13. songdogtech
    Member
    Posted 2 years ago #

    Hmm.... Paste the code of the whole index.php again....

  14. Melee VIII
    Member
    Posted 2 years ago #

    It's the exact same, just with the new query added after <?php }; ?> and before the <?php endwhile; ?>.

  15. songdogtech
    Member
    Posted 2 years ago #

    I'll test it on my local install....

  16. songdogtech
    Member
    Posted 2 years ago #

    Simplfied and tested: http://wordpress.pastebin.com/m4fea32ed

    Change your cat numbers to what you want, as well as showposts. Duplicate lines 15 to 24 for another query and put it above the <?php else: ?>.

  17. Melee VIII
    Member
    Posted 2 years ago #

    That doesn't even work with one for me.

  18. Melee VIII
    Member
    Posted 2 years ago #

    I messed a bit with that and some other examples and got it to work now, thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic