Advertisement
firoze

another pagination without any plugin

Aug 7th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. // another pagination
  2.  
  3. // show this code where need to show pagination
  4.  
  5. <?php pagination(); ?>
  6.  
  7. ***************************************************************************
  8. // call this functions.php
  9.  
  10.  
  11.  
  12. function pagination($pages = '', $range = 4)
  13. {
  14. $showitems = ($range * 2)+1;
  15.  
  16. global $paged;
  17. if(empty($paged)) $paged = 1;
  18.  
  19. if($pages == '')
  20. {
  21. global $wp_query;
  22. $pages = $wp_query->max_num_pages;
  23. if(!$pages)
  24. {
  25. $pages = 1;
  26. }
  27. }
  28.  
  29. if(1 != $pages)
  30. {
  31. echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
  32. if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
  33. if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";
  34.  
  35. for ($i=1; $i <= $pages; $i++)
  36. {
  37. if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
  38. {
  39. echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
  40. }
  41. }
  42.  
  43. if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";
  44. if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
  45. echo "</div>\n";
  46. }
  47. }
  48.  
  49.  
  50. *********************************************************************************************************************
  51.  
  52. // this is style sheet that i have stylized
  53.  
  54. .pagination{width:100%;}
  55. .pagination a{-moz-border-bottom-colors: none;
  56. -moz-border-left-colors: none;
  57. -moz-border-right-colors: none;
  58. -moz-border-top-colors: none;
  59. background: #f7f7f7 linear-gradient(to bottom, #fff, #eee) repeat scroll 0 0 border-box;
  60. border-color: rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.3);
  61. border-image: none;
  62. border-style: solid;
  63. border-width: 1px;
  64. color: #666;
  65. margin-right: 5px;
  66. padding: 5px 10px;
  67. text-shadow: 0 1px 0 #fff;}
  68.  
  69. .pagination a:hover{-moz-border-bottom-colors: none;
  70. -moz-border-left-colors: none;
  71. -moz-border-right-colors: none;
  72. -moz-border-top-colors: none;
  73. background: #009dd8 linear-gradient(to bottom, #00b4f5, #008dc5) repeat scroll 0 0 border-box;
  74. border-color: rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.4);
  75. border-image: none;
  76. border-style: solid;
  77. border-width: 1px;
  78. color: #fff;
  79. text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.2);}
  80.  
  81. .pagination a.inactive{}
  82. .pagination span{-moz-border-bottom-colors: none;
  83. -moz-border-left-colors: none;
  84. -moz-border-right-colors: none;
  85. -moz-border-top-colors: none;
  86. background: #009dd8 linear-gradient(to bottom, #00b4f5, #008dc5) repeat scroll 0 0 border-box;
  87. border-color: rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.4);
  88. border-image: none;
  89. border-style: solid;
  90. border-width: 1px;
  91. color: #fff;
  92. margin-right:5px;
  93. padding: 5px 11px;
  94. text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.2);}
  95. .pagination span.current{-moz-border-bottom-colors: none;
  96. -moz-border-left-colors: none;
  97. -moz-border-right-colors: none;
  98. -moz-border-top-colors: none;
  99. background: #009dd8 linear-gradient(to bottom, #00b4f5, #008dc5) repeat scroll 0 0 border-box;
  100. border-color: rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.4);
  101. border-image: none;
  102. border-style: solid;
  103. border-width: 1px;
  104. color: #fff;
  105. padding: 5px 11px;
  106. text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.2);}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement