Hey everyone,
Running into a (small) issue that's bugging me. Basically, I want to display each category on the site in it's own div, and then inside that div, have a list of the 3 most recent posts in that category. So, ideally, a result should be output like this:
<div class="categoryslug">
<h3>Category Name</h3>
<p>Category Description</p>
<ul>
<li><a href="linktopost1">Post 1</a></li>
<li><a href="linktopost2">Post 2</a></li>
<li><a href="linktopost3">Post 3</a></li>
</ul>
</div>
This is what I have so far:
$args=array(
'orderby' => 'name',
'parent' => '5',
'order' => 'ASC',
'hide_empty' => '0'
);
$categories=get_categories($args);
foreach($categories as $category) {
echo '
<div class="' . $category->slug . '">
<h3>' . $category->name . '</h3>
<p>' . $category->description .'</p>
<ul>
<li>Link to post 1 should go here</li>
<li><a href="' . get_category_link( $category->term_id ) . '">More...</a></li>
</ul>
</div>
';
}
Any suggestions on how to do what I'm trying to do? I tried to do a loop in there using get_posts but failed miserably.
Thanks so much for your help!