Advertisement
dimitriskl

Pagination Example

Jun 15th, 2020
830
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. ?>
  2. <div id="main-content" class="container content-wrapper body-content">
  3.     <?php
  4.     if ( have_posts() ) {
  5.         $post_count = wp_count_posts('project')->publish;
  6.         $post_count = (int)$post_count;
  7.         $total_pages = $post_count / 8;
  8.         if($post_count % 8 != 0){
  9.             $total_pages += 1;
  10.         }
  11.         ?>
  12.         <h3 id="top-header"><?php echo __('Projects', 'rbscp'); ?></h3>
  13.         <?php
  14.         while(have_posts()) : the_post();
  15.             get_template_part('blocks/archive', 'block');
  16.         endwhile;
  17.         ?>
  18.  
  19.         <!-- Add pagination -->
  20.         <div class="pagination">
  21.             <?php echo paginate_links( array(
  22.                 'base'         => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
  23.                 'total'        => $total_pages,
  24.                 'current'      => max( 1, get_query_var( 'paged' ) ),
  25.                 'format'       => '?paged=%#%',
  26.                 'show_all'     => false,
  27.                 'type'         => 'plain',
  28.                 'end_size'     => 2,
  29.                 'mid_size'     => 1,
  30.                 'prev_next'    => true,
  31.                 'prev_text'    => sprintf( '<i class="fas fa-chevron-left"></i>'),
  32.                 'next_text'    => sprintf( '<i class="fas fa-chevron-right"></i>'),
  33.                 'add_args'     => false,
  34.                 'add_fragment' => '',
  35.             ) ); ?>
  36.         </div>
  37.         <?php
  38.     } else {
  39.         esc_html_e('Sorry, no Projects were found', 'rbscp');
  40.     }
  41.    
  42.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement