Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php $cats = array('film-reviews','poetry'); //an array with category slugs;
- foreach ($cats as $cat_slug) :
- $cat = get_term_by('slug',$cat_slug,'category');
- $cat_id = $cat->term_id;
- $args = array(
- 'posts_per_page' => 3, // max number of post per category
- 'category__in' => array($cat_id)
- );
- $cat_query = new WP_Query($args);
- if ($cat_query->have_posts()) :
- echo '<h2>'.$cat->name.'</h2>';
- while ($cat_query->have_posts()) : $cat_query->the_post(); ?>
- <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
- <?php the_excerpt(); ?>
- <?php endwhile; ?>
- <?php else :
- echo '<h2>No Posts for '.$cat->name.'</h2>';
- endif;
- wp_reset_query(); ?>
- <?php endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement