分頁類-尾部頁碼導航

WBOY
發布: 2016-07-25 09:01:02
原創
1356 人瀏覽過
分頁類-尾部頁碼導航
  1. /**
  2. * 產生Comment的尾部分頁導航
  3. * @author 李俊
  4. *
  5. */
  6. class cmtTail{
  7. private $currentPage;
  8. private $🎜> private $currentPage;
  9. private $🎜> 🎜> /**
  10. * 產生頁碼導覽--總控函數
  11. * @param string $currentPage 目前頁碼
  12. * @param string $totalPage 總頁數
  13. * @throws Exception 頁碼小於1將會拋出例外
  14. * @return string
  15. */
  16. function __do($currentPage, $totalPage) {
  17. $this->currentPage=$currentPage;
  18. $this->totalPage=$totalPage=$currentPage;
  19. $this->totalPage=$totalPage; if($this->totalPage if($this->currentPage==1){//當前頁是第一頁
  20. $str= '上一頁'.$this->currentTag();
  21. for ($i = 2; $i totalPage; $i++) {
  22. $str=$str.$this- >commonTag($i);
  23. }
  24. $str=$str.$this->next();
  25. }elseif ($this->currentPage==$this->totalPage){//已跳至最後一頁
  26. $str=$this->up();
  27. for ($i = 1; $i totalPage-1; $i++) {
  28. $ str=$str.$this->commonTag($i);
  29. }
  30. $str=$str.$this->currentTag();
  31. $str=$str.$this->next ();
  32. }else{
  33. $str=$this->up();
  34. for($i=1; $icurrentPage; $i++){
  35. $ str=$str.$this->commonTag($i);
  36. }
  37. $str=$str.$this->currentTag();//產生目前頁標籤
  38. for ($i = $this->currentPage+1; $i totalPage; $i++) {
  39. $str=$str.$this->commonTag($i);
  40. }
  41. $str =$str.$this->next();
  42. }
  43. }elseif ($this->totalPage>10){//頁碼大於10
  44. if($this->currentPage==1) {//8+2
  45. $str='上一頁'.$this->currentTag();
  46. for ($i = 2; $i $ str=$str.$this->commonTag($i);
  47. }
  48. $str=$str.'...';//新增省略號
  49. $str=$str.$this- >commonTag($this->totalPage-1);
  50. $str=$str.$this->commonTag($this->totalPage);
  51. }elseif($this->currentPage==$this- >totalPage) {//目前為最後一頁
  52. $str=$this->up();
  53. $str=$str.$this->commonTag(1);
  54. $str=$ str.'...';//新增省略號
  55. for ($i = $this->totalPage-6; $i totalPage; $i++) {
  56. $str=$str. $this->commonTag($i);
  57. }
  58. $str=$str.$this->currentTag();
  59. $str=$str.$this->next();
  60. }else {
  61. if ($this->currentPage $str=$this->up();
  62. for ($i = 1; $i currentPage ; $i++) {
  63. $str=$str.$this->commonTag($i);
  64. }
  65. $str=$str.$this->currentTag();
  66. for ( $i = $this->currentPage+1; $i $str=$str.$this->commonTag($i);
  67. }
  68. $str= $str.'...';//新增省略號
  69. $str=$str.$this->commonTag($this->totalPage);
  70. $str=$str.$this->next( );
  71. }else {
  72. if ($this->currentPage>=$this->totalPage-4) {
  73. $str=$this->up();
  74. $str=$ str.$this->commonTag(1);
  75. $str=$str.'...';//新增省略號
  76. for ($i = $this->totalPage-6; $i currentPage; $i++) {
  77. $str=$str.$this->commonTag($i);
  78. }
  79. $str=$str.$this->currentTag();
  80. for ($i = $this->currentPage+1; $i totalPage; $i++) {
  81. $str=$str.$this->commonTag($i);
  82. }
  83. $str=$str.$this->next();
  84. }elseif ($this->currentPagetotalPage-4){//1+5+1
  85. $str=$this->up();
  86. $str=$str.$this->commonTag(1);
  87. $str=$str.'...';//新增省略號
  88. $str=$str.$this->commonTag($this->currentPage-2);
  89. $str=$str.$this->commonTag($this->currentPage-1);
  90. $ str=$str.$this->currentTag();
  91. $str=$str.$this->commonTag($this->currentPage+1);
  92. $str=$str.$this-> commonTag($this->currentPage+2);
  93. $str=$str.'...';//新增省略號
  94. $str=$str.$this->commonTag($this->totalPage );
  95. $str=$str.$this->next();
  96. }
  97. };
  98. }
  99. }elseif ($this->totalPage throw new Exception("頁不可能小於1");
  100. }
  101. return $str;
  102. }
  103. /**
  104. * 一般標籤
  105. * @param int $param 頁碼
  106. * @return string
  107. */
  108. function commonTag($param) {
  109. return ''.$param.' a>' ;
  110. }
  111. /**
  112. * 產生目前頁標籤
  113. * @param int $param 頁碼
  114. * @return string
  115. */
  116. function currentTag() {
  117. return ''.$this->currentPage .' ';
  118. }
  119. /**
  120. * 產生下一頁標籤
  121. * @param int $param 下一頁頁碼
  122. * @return string
  123. */
  124. function next() {
  125. if ($this->currentPage==$this-> TotalPage) {
  126. return '下頁';
  127. }
  128. return '下一頁';
  129. }
  130. / * *
  131. * 產生上一頁標籤
  132. * @param int $param 上一頁頁碼
  133. * @return string
  134. */
  135. function up() {
  136. if ($this->currentPage==1){
  137. return '上頁';
  138. }else{
  139. return ' currentPage-1).'">上一頁
  140. ';
  141. }
  142. }
  143. /**
  144. * 實例化cmtTail,
  145. * 功能:產生Comment的尾部分頁導航
  146. * @param string $currentPage 目前頁碼
  147. * @param string $totalPage 總頁數
  148. * @return string 回傳html標籤字串
  149. */
  150. 靜態函數GO($currentPage, $totalPage) {
  151. $p=new cmtTail();
  152. return $p-> ;__do($currentPage, $totalPage);
  153. }
  154. }
複製程式碼


來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!