Skip to main content
deleted 28 characters in body
Source Link
Michael
  • 8.4k
  • 3
  • 29
  • 31

get the child categories, using get_categories(); then loop through them with a foreach loop, using WP_Query() :

<?php  $cats = get_categories('child_of='.get_query_var('cat')); 
  
    foreach ($cats as $cat) :

    $args = array(
    'posts_per_page' => 3, // max number of post per category
    'category__in' => array($cat->term_id)
    );
    $my_query = new WP_Query($args); 

        if ($my_query->have_posts()) : 
        echo '<h3>'.$cat->name.'</h3>';
     
        while ($my_query->have_posts()) : $my_query->the_post(); ?>     
        <?php /*general loop output; for instance: */ ?>
        <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>    <br />  
    
        <?php endwhile; ?>
        
        <?php else : 
        echo 'No Posts for '.$cat->name;                
        endif; 
     
    wp_reset_query(); 
     
    endforeach; ?>

get the child categories, using get_categories(); then loop through them with a foreach loop, using WP_Query() :

<?php  $cats = get_categories('child_of='.get_query_var('cat')); 
  
    foreach ($cats as $cat) :

    $args = array(
    'posts_per_page' => 3, // max number of post per category
    'category__in' => array($cat->term_id)
    );
    $my_query = new WP_Query($args); 

        if ($my_query->have_posts()) : 
        echo '<h3>'.$cat->name.'</h3>';
     
        while ($my_query->have_posts()) : $my_query->the_post(); ?>     
        <?php /*general loop output; for instance: */ ?>
        <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>    <br />  
    
        <?php endwhile; ?>
        
        <?php else : 
        echo 'No Posts for '.$cat->name;                
        endif; 
     
    wp_reset_query(); 
     
    endforeach; ?>

get the child categories, using get_categories(); then loop through them with a foreach loop, using WP_Query() :

<?php  $cats = get_categories('child_of='.get_query_var('cat')); 
  
    foreach ($cats as $cat) :

    $args = array(
    'posts_per_page' => 3, // max number of post per category
    'category__in' => array($cat->term_id)
    );
    $my_query = new WP_Query($args); 

        if ($my_query->have_posts()) : 
        echo '<h3>'.$cat->name.'</h3>';
     
        while ($my_query->have_posts()) : $my_query->the_post(); ?>     
        <?php /*general loop output; for instance: */ ?>
        <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>    <br />  
    
        <?php endwhile; ?>
        
        <?php else : 
        echo 'No Posts for '.$cat->name;                
        endif; 
            
    endforeach; ?>
Source Link
Michael
  • 8.4k
  • 3
  • 29
  • 31

get the child categories, using get_categories(); then loop through them with a foreach loop, using WP_Query() :

<?php  $cats = get_categories('child_of='.get_query_var('cat')); 
  
    foreach ($cats as $cat) :

    $args = array(
    'posts_per_page' => 3, // max number of post per category
    'category__in' => array($cat->term_id)
    );
    $my_query = new WP_Query($args); 

        if ($my_query->have_posts()) : 
        echo '<h3>'.$cat->name.'</h3>';
     
        while ($my_query->have_posts()) : $my_query->the_post(); ?>     
        <?php /*general loop output; for instance: */ ?>
        <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>    <br />  
    
        <?php endwhile; ?>
        
        <?php else : 
        echo 'No Posts for '.$cat->name;                
        endif; 
     
    wp_reset_query(); 
    
    endforeach; ?>