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
    • 446
    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.

    1. <table>
    2. <thead>
    3. <!----- Initializing table head -->
    4. <tr>
    5. <th>S. NO.</th>
    6. <th>Vacancy</th>
    7. <th>Details</th>
    8. <th></th>
    9. </tr>
    10. </thead>
    11. <tbody>
    12.  
    13. <!--------- PHP CODE START HERE -->
    14. <?php
    15. $inc = 0;
    16. // GET THE CURRENT PAGE NUMBER
    17. $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    18. $args = array('post_type' => 'Vacancy',
    19. 'posts_per_page' => 20, // NUMBER ITEMS PER PAGE
    20. 'paged' => $paged,
    21. 'order' => 'desc');
    22. $loop = new WP_Query( $args);
    23. //Display the contents
    24. while ( $loop->have_posts() ) :
    25. $loop->the_post();
    26. $content = get_the_content();
    27. $url = get_bloginfo('wpurl');
    28. $inc++;
    29. ?>
    30.  
    31.  
    32. <tr>
    33. <td><?php echo $inc; ?></td>
    34. <td><strong><?php the_title(); ?></strong></td>
    35. <td><?php the_excerpt(); ?></td>
    36. <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>
    37. </tr>
    38. <?php endwhile; ?>
    39.  
    40. <!---- CODE TO SHOW PAGING BOTTOM OF PAGE -->
    41. <tr>
    42. <td colspan="4" align="center">
    43. <?php
    44. global $loop;
    45. $big = 999999999; // need an unlikely integer
    46. echo paginate_links( array(
    47. 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    48. 'format' => '?paged=%#%',
    49. 'current' => max( 1, get_query_var('paged') ),
    50. 'total' => $loop->max_num_pages
    51. ) );
    52. ?>
    53. </td>
    54. </tr>
    55. </tbody>
    56. </table>

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: