I have below code here. It's display that I want category names and description as well. Now I need to display post that they have inside their categories. How I do it?
<?php
$args = array(
'orderby' => 'id',
'hide_empty'=> 0,
'child_of' => 10, //Child From Boxes Category
);
$categories = get_categories($args);
foreach ($categories as $cat) {
echo '<div class="one_fourth">';
echo '<h1 class="valignmiddle uppercase title-bold">'.$cat->name.'<img src="'.$cat->term_icon.'" alt="" class="alignleft"/>'.'<br />'.'<span class="solutions">'.$cat->description.'</span>'.'</h1>';
$post = array( 'posts_per_page' => 5, 'offset'=> 1, 'category' => 10 );
$posts_array = get_posts( $post );
echo '</div>';
}
?>
If there have any other way to get child category post and display child category name and posts in loop. Please let me to know here.
After I solved this. I think this will help for you.
<?php
$args = array(
'orderby' => 'id',
'hide_empty'=> 0,
'child_of' => 5, //Child From Boxes Category
);
$categories = get_categories($args);
foreach ($categories as $cat) {
echo '<div style="width:20%;float:left;">';
echo '<h1 class="valignmiddle uppercase title-bold">'.$cat->name.'<img src="'.$cat->term_icon.'" alt="" class="alignleft"/>'.'<br />'.'<span class="solutions">'.$cat->description.'</span>'.'</h1>';
//echo '<br />';
$args2= array("orderby"=>'name', "category" => $cat->cat_ID); // Get Post from each Sub-Category
$posts_in_category = get_posts($args2);
foreach($posts_in_category as $current_post) {
echo '<span>';
?>
<li type='none' style='list-style-type: none !important;'><a href="<?=$current_post->guid;?>"><?='+ '.$current_post->post_title;?></a></li>
<?php
echo '</span>';
}
echo '</div>';
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With