Paging-navigation of the ending page number

Source: Internet
Author: User
Paging-navigation of the ending page number
Paging-navigation of the ending page number

  1. /**
  2. * Generate Comment navigation by page at the end
  3. * @ Author Li Jun
  4. *
  5. */
  6. Class cmtTail {
  7. Private $ currentPage;
  8. Private $ totalPage;
  9. /**
  10. * Generate page number navigation-General control function
  11. * @ Param string $ currentPage current page number
  12. * @ Param string $ total number of pages on totalPage
  13. * @ Throws Exception if the page number is smaller than 1, an Exception is 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
  20. If ($ this-> currentPage = 1) {// The current page is the first page
  21. $ Str = 'preview'. $ 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) {// You have 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 tab
  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) {// page number greater than 10
  45. If ($ this-> currentPage = 1) {// 8 + 2
  46. $ Str = 'preview'. $ this-> currentTag ();
  47. For ($ I = 2; $ I <= 8; $ I ++ ){
  48. $ Str = $ str. $ this-> commonTag ($ I );
  49. }
  50. $ Str = $ str. '...'; // add a ellipsis
  51. $ Str = $ str. $ this-> commonTag ($ this-> totalPage-1 );
  52. $ Str = $ str. $ this-> commonTag ($ this-> totalPage );
  53. } Elseif ($ this-> currentPage = $ this-> totalPage) {// The Last Page
  54. $ Str = $ this-> up ();
  55. $ Str = $ str. $ this-> commonTag (1 );
  56. $ Str = $ str. '...'; // add a ellipsis
  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 a ellipsis
  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 a ellipsis
  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 a 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 a ellipsis
  98. $ Str = $ str. $ this-> commonTag ($ this-> totalPage );
  99. $ Str = $ str. $ this-> next ();
  100. }
  101. };
  102. }
  103. } Elseif ($ this-> totalPage <= 0 ){
  104. Throw new Exception ("The page cannot be smaller than 1 ");
  105. }
  106. Return $ str;
  107. }
  108. /**
  109. * General labels
  110. * @ Param int $ param page number
  111. * @ Return string
  112. */
  113. Function commonTag ($ param ){
  114. Return ''. $ param .'';
  115. }
  116. /**
  117. * Generate the current tab
  118. * @ Param int $ param page number
  119. * @ Return string
  120. */
  121. Function currentTag (){
  122. Return''. $ This-> currentPage .'';
  123. }
  124. /**
  125. * Generate the next page tag
  126. * @ Param int $ Next Page number of param
  127. * @ Return string
  128. */
  129. Function next (){
  130. If ($ this-> currentPage ==$ this-> totalPage ){
  131. Return 'next page ';
  132. }
  133. Return 'currentpage + 1). '"> Next Page ';
  134. }
  135. /**
  136. * Generate a previous page tag
  137. * @ Param int $ param previous page number
  138. * @ Return string
  139. */
  140. Function up (){
  141. If ($ this-> currentPage = 1 ){
  142. Return 'previous page ';
  143. } Else {
  144. Return 'currentpage-1). '"> Previous Page ';
  145. }
  146. }
  147. /**
  148. * Instantiate cmtTail,
  149. * Function: generate Comment navigation by page at the end
  150. * @ Param string $ currentPage current page number
  151. * @ Param string $ total number of pages on totalPage
  152. * @ Return string returns the html tag string
  153. */
  154. Static function GO ($ currentPage, $ totalPage ){
  155. $ P = new cmtTail ();
  156. Return $ p->__ do ($ currentPage, $ totalPage );
  157. }
  158. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.