分页类——尾部页码导航

WBOY
发布: 2016-07-25 09:01:02
原创
1357 人浏览过
分页类——尾部页码导航
  1. /**
  2. * 生成Comment的尾部分页导航
  3. * @author 李俊
  4. *
  5. */
  6. class cmtTail{
  7. private $currentPage;
  8. private $totalPage;
  9. /**
  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;
  19. 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.'';
  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 '上一页';
  140. }
  141. }
  142. /**
  143. * 实例化cmtTail,
  144. * 功能:生成Comment的尾部分页导航
  145. * @param string $currentPage 当前页码
  146. * @param string $totalPage 总页数
  147. * @return string 返回html标签字符串
  148. */
  149. static function GO($currentPage, $totalPage) {
  150. $p=new cmtTail();
  151. return $p->__do($currentPage, $totalPage);
  152. }
  153. }
复制代码


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!