Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create pagination with wordpress post?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 394
    Comment on it

    Hello Friends,

    In Wordpress if you listing post on your page and wants to setup pagination on the pages. Please review the below code, I am listing vacancy and you can make your changes as per code requirement.

     <table>
                  <thead>
                   <!----- Initializing table head --> 
                    <tr>
                      <th>S. NO.</th>
                      <th>Vacancy</th>                 
                      <th>Details</th>
                      <th></th>
                    </tr>
                  </thead>
                  <tbody>
    
                 <!--------- PHP CODE START HERE -->
                 <?php 
                  $inc = 0;
                  // GET THE CURRENT PAGE NUMBER
                  $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
                  $args = array('post_type' => 'Vacancy',
                    'posts_per_page'  => 20,        // NUMBER ITEMS PER PAGE    
                    'paged'           => $paged,
                    'order'           => 'desc');
                  
                  $loop = new WP_Query( $args);
                  //Display the contents
                  while ( $loop->have_posts() ) : 
                  $loop->the_post();
                  $content = get_the_content();
                  $url = get_bloginfo('wpurl');
                  $inc++;           
                  ?>
    
    
                  <tr>
                    <td><?php echo $inc; ?></td>
                    <td><strong><?php the_title(); ?></strong></td>
                    <td><?php the_excerpt(); ?></td>
                    <td><a href="<?php echo $url.'/vacancy-detail/?id='.$post->ID; ?>">View More</a><i aria-hidden="true" class="fa fa-angle-double-right"></i></td>
                  </tr>  
                  <?php endwhile; ?>
    
                <!---- CODE TO SHOW PAGING BOTTOM OF PAGE -->
                  <tr>
                    <td colspan="4" align="center">
                      <?php
                        global $loop;
                        $big = 999999999; // need an unlikely integer
                        echo paginate_links( array(
                        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                        'format' => '?paged=%#%',
                        'current' => max( 1, get_query_var('paged') ),
                        'total' => $loop->max_num_pages
                        ) );
                      ?>              
                    </td>
                  </tr>             
             </tbody>
    </table>

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: