Wordpress Native Pagination Links With Page Number No Plugin Needed


/ Published in: PHP
Save to your folder(s)

Create navigation links without the need of a plugin, using paginate_links function of wordpress core.


Copy this code and paste it in your HTML
  1. // put it in your functions.php of your theme, enjoy :)
  2.  
  3. function show_pagination_links()
  4. {
  5. global $wp_query;
  6.  
  7. $page_tot = $wp_query->max_num_pages;
  8. $page_cur = get_query_var( 'paged' );
  9. $big = 999999999;
  10.  
  11. if ( $page_tot == 1 ) return;
  12.  
  13. echo paginate_links( array(
  14. 'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ), // need an unlikely integer cause the url can contains a number
  15. 'format' => '?paged=%#%',
  16. 'current' => max( 1, $page_cur ),
  17. 'total' => $page_tot,
  18. 'prev_next' => true,
  19. 'end_size' => 1,
  20. 'mid_size' => 2,
  21. 'type' => 'list'
  22. )
  23. );
  24. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.