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.
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; ?>
Melee VIII
Member
Posted 2 years ago #
It doesn't show any posts at all.
Are you using that loop on a page or page template in a post?
Melee VIII
Member
Posted 2 years ago #
In index.php? Post your index.php at WordPress Pastebin and then put the link here.
Melee VIII
Member
Posted 2 years ago #
See pastebin; it's better to modify the existing WP loop than run a new query.
Melee VIII
Member
Posted 2 years ago #
But if I want to add a new one?
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; ?>
Melee VIII
Member
Posted 2 years ago #
Melee VIII
Member
Posted 2 years ago #
The new query doesn't show anything at all...
Hmm.... Paste the code of the whole index.php again....
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; ?>.
I'll test it on my local install....
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: ?>.
Melee VIII
Member
Posted 2 years ago #
That doesn't even work with one for me.
Melee VIII
Member
Posted 2 years ago #
I messed a bit with that and some other examples and got it to work now, thanks.