I am new to Wordpress and been pulling my hair out trying to create a category loop. The loop is supposed to:
- loop through all categories
- echo out the category name (with link to
- echo out the last 5 posts in that category (with permalink to post)
The html for each would be
<div class="cat_wrap">
<div class="cat_name">
<a href="<?php get_category_link( $category_id ); ?>">Cat Name</a>
</div>
<ul class="cat_items">
<li class="cat_item">
<a href="permalink">cat item 1</a>
</li>
<li class="cat_item">
<a href="permalink">cat item 2</a>
</li>
<li class="cat_item">
<a href="permalink">cat item 3</a>
</li>
<li class="cat_item">
<a href="permalink">cat item 4</a>
</li>
<li class="cat_item">
<a href="permalink">cat item 5</a>
</li>
</ul>
</div>
Please help
Take a look at this other Stackoverflow thread:
https://wordpress.stackexchange.com/questions/346/loop-through-custom-taxonomies-and-display-posts/233948#233948
I posted an answer that I use in production and works like a charm.
Just remember to adjust the arguments to display only 5 posts, instead of all.
Add 'showposts' => 5 to your current array of arguments in the loop that iterates through the posts of each category.
Oops, missed that you wanted 5 posts
Hy keeping things simple here is how you can solve it
I have made this bit of code to loop through the nested categories. Sharing.