Advertisement
keha76

WordPress | Category Posts

Mar 15th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?php
  2.  
  3. // Put this in your template file
  4. $category_ids = get_all_category_ids();
  5. foreach( $category_ids as $cat_id ) {
  6.     echo category_description( $cat_id );
  7.     list_cat_posts( $cat_id );
  8. }
  9.  
  10. // Put this in your functions.php
  11. function list_cat_posts( $category_id ) {
  12.    
  13.     $args = array(
  14.         'category__in' => $category_id,
  15.         'posts_per_page' => -1
  16.     );
  17.    
  18.     $cat_query = new WP_Query( $args );
  19.    
  20.     if( $cat_query->have_posts() ) {
  21.         while( $cat_query->have_posts() ) {
  22.             $cat_query->the_post();
  23.            
  24.             // Output each post in the category here using standard template tags
  25.             echo '<h6><a href="">' . get_the_title() . '</a></h6>';
  26.         }
  27.     }
  28.    
  29.     wp_reset_query();
  30. }
  31.  
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement