Skip to main content
added 2019 characters in body
Source Link
Chris
  • 453
  • 2
  • 15
  • 31

P.S. My theme includes this function to provide pagination. It is used on both blogs and the search results page.

function semi_pagination( $pages = '', $range = 4 ) { $showitems = ($range * 2) + 1; global $paged; if( empty( $paged ) ) $paged = 1; if( $pages == '' ) { global $wp_query; $pages = $wp_query->max_num_pages; if(!$pages) { $pages = 1; } } if(1 != $pages) { echo "<div class=\"pagination pagination-centered clearfix nobottommargin topmargin\" style=\"font-size: 13px;\"><ul>"; if( $paged > 2 && $paged > $range + 1 && $showitems < $pages ) echo "<li><a href='" . get_pagenum_link( 1 ) . "'>&lArr;</a></li>"; if( $paged > 1 && $showitems < $pages ) echo "<li><a href='" . get_pagenum_link( $paged - 1 ) . "'>&laquo;</a></li>"; for ( $i = 1; $i <= $pages; $i++ ) { if ( 1 != $pages && ( !( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems )) { echo ( $paged == $i ) ? "<li><span class=\"active\">" . $i . "</span></li>" : "<li><a href='" . get_pagenum_link( $i ) . "'>" . $i . "</a></li>"; } } if ( $paged < $pages && $showitems < $pages ) echo "<li><a href=\"" . get_pagenum_link( $paged + 1 ) . "\">&raquo;</a></li>"; if ( $paged < $pages-1 && $paged + $range - 1 < $pages && $showitems < $pages ) echo "<li><a href='" . get_pagenum_link( $pages ) . "'>&rArr;</a></li>"; echo "</ul></div>\n"; } } 

P.S. My theme includes this function to provide pagination. It is used on both blogs and the search results page.

function semi_pagination( $pages = '', $range = 4 ) { $showitems = ($range * 2) + 1; global $paged; if( empty( $paged ) ) $paged = 1; if( $pages == '' ) { global $wp_query; $pages = $wp_query->max_num_pages; if(!$pages) { $pages = 1; } } if(1 != $pages) { echo "<div class=\"pagination pagination-centered clearfix nobottommargin topmargin\" style=\"font-size: 13px;\"><ul>"; if( $paged > 2 && $paged > $range + 1 && $showitems < $pages ) echo "<li><a href='" . get_pagenum_link( 1 ) . "'>&lArr;</a></li>"; if( $paged > 1 && $showitems < $pages ) echo "<li><a href='" . get_pagenum_link( $paged - 1 ) . "'>&laquo;</a></li>"; for ( $i = 1; $i <= $pages; $i++ ) { if ( 1 != $pages && ( !( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems )) { echo ( $paged == $i ) ? "<li><span class=\"active\">" . $i . "</span></li>" : "<li><a href='" . get_pagenum_link( $i ) . "'>" . $i . "</a></li>"; } } if ( $paged < $pages && $showitems < $pages ) echo "<li><a href=\"" . get_pagenum_link( $paged + 1 ) . "\">&raquo;</a></li>"; if ( $paged < $pages-1 && $paged + $range - 1 < $pages && $showitems < $pages ) echo "<li><a href='" . get_pagenum_link( $pages ) . "'>&rArr;</a></li>"; echo "</ul></div>\n"; } } 
Source Link
Chris
  • 453
  • 2
  • 15
  • 31

Custom post type blog pagination conflict

I have a custom post type called 'emp_case-studies' and it has a page archive. Here is the code for archive-emp_case-studies.php:

<?php $blog = $wp_query; $wp_query= null; $args= null; $args = array( 'post_type' => 'emp_case-studies' ); $postsperpage = 5; $offset = $paged == 0 ? 0 : ($paged-1)*$postsperpage; $paging = array( 'posts_per_page' => $postsperpage, 'offset' => $offset ); $ordering = array( 'orderby' => 'ID', 'order' => 'DESC' ); $args = array_merge($args, $ordering, $paging); $wp_query = new WP_Query($args); ?> <?php get_header(); get_template_part( 'include/content', 'head' ); ?> <div class="postcontent nobottommargin<?php if( semi_option( 'blog_sidebar' ) == 'left' ) { echo ' col_last'; } ?> clearfix"> <?php if ( $wp_query->have_posts() ) : ?> <div id="posts" class="small-posts clearfix"> <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?> <div id="post-<?php $wp_query->ID; ?>" <?php post_class('entry clearfix'); ?>> <?php get_template_part( 'include/blog/news/post', 'standard' ); ?> </div> <?php endwhile; get_template_part( 'include/blog/navigation' ); ?></div><?php else : get_template_part( 'include/blog/error' ); endif; $wp_query = $temp; ?> </div> <?php get_sidebar('casestudies'); get_template_part( 'include/content', 'foot' ); get_footer(); ?> 

I had a terrible time getting pagination to work correctly so that I could have: archive page: /case-studies single page: /case-studies/post-title

Using the custom query got me the majority of the way. Page 1 and 2 worked fine, but page 3 onward did not. I found a post on the official WordPress forum with someone having the same issue. It was solved by changing Settings > Reading > Blog pages show at most to 1. This worked for me too. All the pagination on my custom post type archive pages work perfectly.

However, it means that now my blog and search results page are only showing one post per page.

Is there any way I can change this to 5 posts per page?