hmbashar

Numbering pagination Coding

Apr 23rd, 2014
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.19 KB | None | 0 0
  1. /*this code copy than past to functions.php */
  2.  
  3. function pagination($pages = '', $range = 4)
  4.     {  
  5.          $showitems = ($range * 2)+1;  
  6.  
  7.          global $paged;
  8.          if(empty($paged)) $paged = 1;
  9.  
  10.          if($pages == '')
  11.          {
  12.              global $wp_query;
  13.              $pages = $wp_query->max_num_pages;
  14.              if(!$pages)
  15.              {
  16.                  $pages = 1;
  17.              }
  18.          }  
  19.  
  20.          if(1 != $pages)
  21.          {
  22.              echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
  23.              if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
  24.              if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";
  25.  
  26.              for ($i=1; $i <= $pages; $i++)
  27.              {
  28.                  if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
  29.                  {
  30.                      echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
  31.                  }
  32.              }
  33.  
  34.              if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";  
  35.              if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
  36.              echo "</div>\n";
  37.          }
  38.     }
  39.  
  40.  
  41.  
  42. /* code copy than past stylesheet*/
  43.  
  44. /* For Pagination Css */
  45. .pagination{
  46. clear:both;
  47. font-size:11px;
  48. line-height:13px;
  49. margin-left:35px;
  50. padding:20px 0;
  51. }
  52. .pagination span, .pagination a{
  53. display:block;
  54. float:left;
  55. margin:2px 2px 2px 0;
  56. padding:6px 9px 5px 9px;
  57. text-decoration:none;
  58. width:auto;
  59. color:#fff;
  60. background:#555;
  61. }
  62. .pagination a:hover{
  63. color:#fff;
  64. background:#3279BB;
  65. }
  66. .pagination .current{
  67. padding:6px 9px 5px 9px;
  68. background:#3279BB;
  69. color:#fff;
  70. }
  71.  
  72.  
  73.  
  74.  
  75. /*copy this code than past your location to pagination ex: index.php */
  76.  
  77. <?php if (function_exists("pagination")) {
  78.         pagination($additional_loop->max_num_pages);
  79.     } ?>
Add Comment
Please, Sign In to add comment