Pagination class - tail page number navigation

WBOY
Release: 2016-07-25 09:01:02
Original
1378 people have browsed it
Pagination class - tail page number navigation
  1. /**
  2. * Generate the tail paging navigation of Comment
  3. * @author Li Jun
  4. *
  5. */
  6. class cmtTail{
  7. private $currentPage;
  8. private $totalPage;
  9. /**
  10. * Generate page number navigation - total control function
  11. * @param string $currentPage current page number
  12. * @param string $totalPage total page number
  13. * @throws Exception If the page number is less than 1, an exception will be thrown
  14. * @return string
  15. */
  16. function __do($currentPage, $totalPage ) {
  17. $this->currentPage=$currentPage;
  18. $this->totalPage=$totalPage;
  19. if($this->totalPage<=10){//The total number of pages is less than or equal to 10 pages
  20. if( $this->currentPage==1){//The current page is the first page
  21. $str='previous page'.$this->currentTag();
  22. for ($i = 2; $i < = $this->totalPage; $i++) {
  23. $str=$str.$this->commonTag($i);
  24. }
  25. $str=$str.$this->next();
  26. } elseif ($this->currentPage==$this->totalPage){//Jumped to the last page
  27. $str=$this->up();
  28. for ($i = 1; $i < ;= $this->totalPage-1; $i++) {
  29. $str=$str.$this->commonTag($i);
  30. }
  31. $str=$str.$this->currentTag() ;
  32. $str=$str.$this->next();
  33. }else{
  34. $str=$this->up();
  35. for($i=1; $i<$this-> currentPage; $i++){
  36. $str=$str.$this->commonTag($i);
  37. }
  38. $str=$str.$this->currentTag();//Generate the current page tag
  39. for ($i = $this->currentPage+1; $i <= $this->totalPage; $i++) {
  40. $str=$str.$this->commonTag($i);
  41. }
  42. $str=$str.$this->next();
  43. }
  44. }elseif ($this->totalPage>10){//The page number is greater than 10
  45. if($this->currentPage==1){ //8+2
  46. $str='previous page'.$this->currentTag();
  47. for ($i = 2; $i <= 8; $i++) {
  48. $str=$str. $this->commonTag($i);
  49. }
  50. $str=$str.'...';//Add ellipses
  51. $str=$str.$this->commonTag($this->totalPage -1);
  52. $str=$str.$this->commonTag($this->totalPage);
  53. }elseif($this->currentPage==$this->totalPage) {//currently Last page
  54. $str=$this->up();
  55. $str=$str.$this->commonTag(1);
  56. $str=$str.'...';//Add ellipses
  57. for ($i = $this->totalPage-6; $i < $this->totalPage; $i++) {
  58. $str=$str.$this->commonTag($i);
  59. }
  60. $str=$str.$this->currentTag();
  61. $str=$str.$this->next();
  62. }else {
  63. if ($this->currentPage<6) {
  64. $str=$this->up();
  65. for ($i = 1; $i < $this->currentPage; $i++) {
  66. $str=$str.$this->commonTag($ i);
  67. }
  68. $str=$str.$this->currentTag();
  69. for ($i = $this->currentPage+1; $i <= 7; $i++) {
  70. $str =$str.$this->commonTag($i);
  71. }
  72. $str=$str.'...';//Add ellipses
  73. $str=$str.$this->commonTag($this ->totalPage);
  74. $str=$str.$this->next();
  75. }else {
  76. if ($this->currentPage>=$this->totalPage-4) {
  77. $str =$this->up();
  78. $str=$str.$this->commonTag(1);
  79. $str=$str.'...';//Add ellipses
  80. for ($i = $this->totalPage-6; $i < $this->currentPage; $i++) {
  81. $str=$str.$this->commonTag($i);
  82. }
  83. $str=$str .$this->currentTag();
  84. for ($i = $this->currentPage+1; $i <= $this->totalPage; $i++) {
  85. $str=$str.$this ->commonTag($i);
  86. }
  87. $str=$str.$this->next();
  88. }elseif ($this->currentPage<$this->totalPage-4){// 1+5+1
  89. $str=$this->up();
  90. $str=$str.$this->commonTag(1);
  91. $str=$str.'...';// Add ellipsis
  92. $str=$str.$this->commonTag($this->currentPage-2);
  93. $str=$str.$this->commonTag($this->currentPage-1);
  94. $str=$str.$this->currentTag();
  95. $str=$str.$this->commonTag($this->currentPage+1);
  96. $str=$str.$this- >commonTag($this->currentPage+2);
  97. $str=$str.'...';//Add ellipses
  98. $str=$str.$this->commonTag($this-> totalPage);
  99. $str=$str.$this->next();
  100. }
  101. };
  102. }
  103. }elseif ($this->totalPage<=0){
  104. throw new Exception("Page impossible Less than 1");
  105. }
  106. return $str;
  107. }
  108. /**
  109. * General tag
  110. * @param int $param page number
  111. * @return string
  112. */
  113. function commonTag($param) {
  114. return ''.$param.'';
  115. }
  116. /**
  117. * Generate current page label
  118. * @param int $param page number
  119. * @return string
  120. */
  121. function currentTag() {
  122. return ''.$this->currentPage.'';
  123. }
  124. /**
  125. * Generate next page label
  126. * @param int $param Next page page number
  127. * @return string
  128. */
  129. function next() {
  130. if ($this->currentPage==$this->totalPage) {
  131. return '下一页';
  132. }
  133. return '下一页';
  134. }
  135. /**
  136. * Generate previous page label
  137. * @param int $param Previous page page number
  138. * @return string
  139. */
  140. function up() {
  141. if ($this->currentPage==1){
  142. return '上一页';
  143. }else{
  144. return '上一页';
  145. }
  146. }
  147. /**
  148. * Instantiate cmtTail,
  149. * Function: Generate tail paging navigation of Comment
  150. * @param string $currentPage current page number
  151. * @param string $totalPage total number of pages
  152. * @return string return html tag string
  153. */
  154. static function GO($currentPage, $totalPage) {
  155. $p=new cmtTail();
  156. return $p->__do($currentPage, $totalPage);
  157. }
  158. }
复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!