Advertisement
shakil97bd

Wordpress Pagination for post

Feb 3rd, 2015
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. ******************** Very Basic Pagination for post ****************
  2.  
  3. //Just past this code after post-loop, in where you want to show post pagination
  4.  
  5. //You can style this pagination button by using a css class in style.css
  6.  
  7. **************** Pagination Code With CSS class **************
  8.  
  9. <div class="older_post"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts') ); ?></div>
  10.  
  11. <div class="newer_post"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>') ); ?></div>
  12.  
  13.  
  14. **************** Pagination Code only **************
  15.  
  16. <?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts') ); ?>
  17.  
  18. <?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>') ); ?>
  19.  
  20. ***************************************************************************************************
  21.  
  22.  
  23.  
  24. ******************** Advance Pagination for post ****************
  25.  
  26. // Fist paste this bellow code in function.php to ragister pagination function
  27.  
  28.  
  29. function pagination($pages = '', $range = 4)
  30. {
  31. $showitems = ($range * 2)+1;
  32.  
  33. global $paged;
  34. if(empty($paged)) $paged = 1;
  35.  
  36. if($pages == '')
  37. {
  38. global $wp_query;
  39. $pages = $wp_query->max_num_pages;
  40. if(!$pages)
  41. {
  42. $pages = 1;
  43. }
  44. }
  45.  
  46. if(1 != $pages)
  47. {
  48. echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
  49. if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
  50. if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";
  51.  
  52. for ($i=1; $i <= $pages; $i++)
  53. {
  54. if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
  55. {
  56. echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
  57. }
  58. }
  59.  
  60. if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";
  61. if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
  62. echo "</div>\n";
  63. }
  64. }
  65.  
  66.  
  67. ****************************************************************
  68.  
  69. //than paste this code after post-loop, in where you want to show post pagination
  70.  
  71. <?php if (function_exists("pagination")) {
  72. pagination($additional_loop->max_num_pages);
  73. } ?>
  74.  
  75. **********************************************************************
  76.  
  77. //Use this code to style your pagination
  78.  
  79. /*for pagination */
  80. .pagination {
  81. clear:both;
  82. padding:20px 0;
  83. position:relative;
  84. font-size:11px;
  85. line-height:13px;
  86. }
  87.  
  88. .pagination span, .pagination a {
  89. display:block;
  90. float:left;
  91. margin: 2px 2px 2px 0;
  92. padding:6px 9px 5px 9px;
  93. text-decoration:none;
  94. width:auto;
  95. color:#fff;
  96. background: #555;
  97. }
  98.  
  99. .pagination a:hover{
  100. color:#fff;
  101. background: #3279BB;
  102. }
  103.  
  104. .pagination .current{
  105. padding:6px 9px 5px 9px;
  106. background: #3279BB;
  107. color:#fff;
  108. }
  109.  
  110.  
  111. ********************************************** End of Advance Pagination ******************************************************
  112.  
  113.  
  114. //You can add pagination with using a wordpress plug-in name "WP-PageNavi".This is a very good and awesome plug-in for page navigation.Download link is bellow...............
  115.  
  116. Download link : https://wordpress.org/plugins/wp-pagenavi/
  117.  
  118.  
  119.  
  120. NOTE : To active this plug-in just paste this code where you want to add pagination..............
  121.  
  122. <?php wp_pagenavi(); ?>
  123.  
  124.  
  125. //You can style this plug in by useing css class
  126.  
  127. ********************************************************** THANKS *****************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement