Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php $cats = array('News Updates', 'Latest Updated Products'); //an array with the category names
- foreach ($cats as $cat) :
- $cat_id = get_cat_ID( $cat ); // http://codex.wordpress.org/Function_Reference/get_cat_ID
- if( $cat_id ) : //only do the next if a the category name reuslted in a cat_id
- echo '<div class="cat-section">';
- $args = array(
- 'posts_per_page' => 3, // max number of post per category
- 'category__in' => array($cat_id) //only posts with directly this cat_id
- );
- $query = new WP_Query($args);
- if ($query->have_posts()) :
- echo '<h2 class="cat-title">' . $cat . '</h2>';
- while ($query->have_posts()) : $query->the_post(); ?>
- <div <?php post_class() ?>>
- <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
- <div class="entry">
- <?php the_excerpt(); ?>
- </div>
- </div>
- <?php endwhile; ?>
- <?php else :
- echo '<h2>No Posts for '.$cat.'</h2>';
- endif;
- wp_reset_postdata(); ?>
- <?php
- echo '</div> <!--end of .cat-section-->';
- endif; // ENDS if( $cat_id ) :
- endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement