Advertisement
alchymyth

cats

Feb 21st, 2013
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Template Name: Category TEST NEW
  4.  *
  5.  * @package WordPress
  6.  * @subpackage Twenty_Eleven
  7.  * @since Twenty Eleven 1.0
  8.  */
  9.  
  10. get_header(); ?>
  11.  
  12.         <section id="primary">
  13.             <div id="content" role="main">
  14. <?php
  15. $all_cats = array( 4,5,6,7,8,16 ); //manual category list
  16. foreach( $all_cats as $cat ) {
  17.  
  18. $latest_post = new WP_Query( array( 'posts_per_page' => 1, 'category__in' => array( $cat ) ) );
  19. $category = get_category($cat); //get category title
  20. if( $latest_post->have_posts() && $category ) : ?>
  21. <h2 class="category-title"><?php echo $category->name; ?></h3>
  22.                    
  23. <?php while( $latest_post->have_posts() ) : $latest_post->the_post(); ?>
  24.  
  25.             <?php get_template_part( 'content', get_post_format() ); ?>
  26.  
  27. <?php endwhile;
  28. else : echo '<p>no post</p>';
  29. endif; wp_reset_postdata();
  30. }
  31. ?>
  32.             </div><!-- #content -->
  33.         </section><!-- #primary -->
  34.  
  35. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement