Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $posts_per_page = 1; // how many posts per term
- $post_count = $i = 0;
- $custom_terms = get_terms( 'issues', array( 'parent' => 0) );
- if($custom_terms) :
- foreach ( $custom_terms as $term ) {
- $post_type_count = (int) get_term_post_type_count( $term->term_id, 'issues', 'news');
- if($post_type_count > $post_count)
- $post_count = $post_type_count;
- $custom_terms[$i]->count_post_type = $post_type_count;
- ++$i;
- }
- if($post_count > 2){
- global $wp_query;
- $wp_query->max_num_pages = ceil( $post_count / $posts_per_page );
- }
- $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
- foreach ( $custom_terms as $custom_term ) :
- $args = array(
- 'post_type' => 'news',
- 'posts_per_page' => $posts_per_page,
- 'paged' => $paged,
- 'tax_query' => array(
- array(
- 'taxonomy' => 'issues',
- 'field' => 'slug',
- 'terms' => $custom_term->slug,
- 'include_children' => 0
- ),
- )
- );
- if( is_paged() ){
- $args['offset'] = ($paged-1) * $posts_per_page;
- }
- $loop = new WP_Query($args);
- if($loop->have_posts()) :
- echo '<h2>Edition '.$custom_term->name.'</h2>';?>
- <h4 class="h6"><?php echo date('l jS F Y'); ?></h4>
- <!-- start of loop -->
- <?php while($loop->have_posts()) : $loop->the_post(); ?>
- <!-- put your loop code here -->
- <p><?php the_title(); ?></p>
- <?php endwhile; ?>
- <!-- end of loop -->
- <?php wp_reset_postdata(); ?>
- <?php endif; ?>
- <?php endforeach; ?>
- <?php endif; ?>
- <!-- pagination functions -->
- <div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
- <div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement