Advertisement
Guest User

Untitled

a guest
Feb 11th, 2013
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. <?php
  2.  
  3. $posts_per_page = 1; // how many posts per term
  4.  
  5. $post_count = $i = 0;
  6. $custom_terms = get_terms( 'issues', array( 'parent' => 0) );
  7.  
  8. if($custom_terms) :
  9. foreach ( $custom_terms as $term ) {
  10. $post_type_count = (int) get_term_post_type_count( $term->term_id, 'issues', 'news');
  11. if($post_type_count > $post_count)
  12. $post_count = $post_type_count;
  13.  
  14. $custom_terms[$i]->count_post_type = $post_type_count;
  15. ++$i;
  16. }
  17.  
  18. if($post_count > 2){
  19. global $wp_query;
  20. $wp_query->max_num_pages = ceil( $post_count / $posts_per_page );
  21. }
  22.  
  23. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  24.  
  25. foreach ( $custom_terms as $custom_term ) :
  26.  
  27. $args = array(
  28. 'post_type' => 'news',
  29. 'posts_per_page' => $posts_per_page,
  30. 'paged' => $paged,
  31. 'tax_query' => array(
  32. array(
  33. 'taxonomy' => 'issues',
  34. 'field' => 'slug',
  35. 'terms' => $custom_term->slug,
  36. 'include_children' => 0
  37. ),
  38. )
  39. );
  40.  
  41. if( is_paged() ){
  42. $args['offset'] = ($paged-1) * $posts_per_page;
  43. }
  44.  
  45. $loop = new WP_Query($args);
  46. if($loop->have_posts()) :
  47. echo '<h2>Edition '.$custom_term->name.'</h2>';?>
  48. <h4 class="h6"><?php echo date('l jS F Y'); ?></h4>
  49.  
  50. <!-- start of loop -->
  51. <?php while($loop->have_posts()) : $loop->the_post(); ?>
  52.  
  53. <!-- put your loop code here -->
  54. <p><?php the_title(); ?></p>
  55.  
  56. <?php endwhile; ?>
  57. <!-- end of loop -->
  58. <?php wp_reset_postdata(); ?>
  59. <?php endif; ?>
  60. <?php endforeach; ?>
  61. <?php endif; ?>
  62.  
  63. <!-- pagination functions -->
  64. <div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
  65. <div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement