ページめくりのリンクリストを生成するphp関数の例

WBOY
リリース: 2016-07-25 08:57:51
オリジナル
928 人が閲覧しました
  1. /**
  2. * ページ番号リストを生成します
  3. * @param int $element_total_count 要素の総数
  4. * @param int $current_page 現在のページ
  5. * @param int $per_page_elem_count ページごとの要素数
  6. * @param int $show_page_num 表示されるページ番号の数リスト内
  7. * @param string $up_down_class 上下のページめくりスタイル
  8. * @param string $num_class 現在のページ番号スタイル
  9. * @param string $href ページリンク
  10. * ページ番号を渡す @param string $page_symbol リンクパラメータ
  11. * @return string
  12. * @site bbs.it-home.org
  13. */
  14. public static function getPageListLink($element_total_count,$current_page=1,$per_page_elem_count=10,
  15. $show_page_num=10,$up_down_class='',$ num_class='',$href='',$page_symbol='p')
  16. {
  17. if(empty($href)) {
  18. //自動取得剔除页码パラメータの页面链接
  19. $page_name =basename($_SERVER[ 'PHP_SELF']);
  20. $params = $_SERVER['QUERY_STRING'];
  21. $params_str = '';
  22. if(!empty($params)) {
  23. $params = str_replace('&', '&', $params);
  24. $params_array =explode('&', $params);
  25. foreach($params_array as $param) {
  26. if(!empty($param)) {
  27. $index = strpos($param, '=');
  28. if($index) {
  29. $key = substr($param, 0, $index);
  30. if($key && $key != $page_symbol)
  31. $params_str .= $param . '&';
  32. }
  33. }
  34. }
  35. }
  36. if(!empty($params_str))
  37. $href = $page_name 。 「?」 。 $params_str;
  38. else
  39. $href = $page_name;
  40. $href = rtrim($href,'&');
  41. }
  42. $prefix = strpos($href,"?") ? "&" : "?";
  43. $prefix .= $page_symbol;
  44. $page_total_count = ceil($element_total_count/$per_page_elem_count);
  45. if(intval($element_total_count)<1 || !isset($element_total_count)) {
  46. return '';
  47. }
  48. if($element_total_count <= $per_page_elem_count)
  49. return '';
  50. if($current_page>$page_total_count)
  51. $current_page = 1;
  52. if(strpos($href,"#")) {
  53. $label = substr($href,strpos($href,"#"));
  54. $href = substr($href,0,strpos($href,"#"));
  55. }
  56. /* 页コード生成 */
  57. if($current_page > ceil($show_page_num/2)) {
  58. $start = $current_page - ceil($show_page_num/2);
  59. $end = (($current_page+ceil($show_page_num/2)) $current_page+ceil($show_page_num/2)-1 : $page_total_count;
  60. } else {
  61. $start = 1;
  62. $end = ($show_page_num>$page_total_count) ? $page_total_count : $show_page_num;
  63. }
  64. if(!empty($num_class))
  65. $num_class_str = ' class="'.$num_class.'"';
  66. else
  67. $num_class_str = '';
  68. $page_num_string = '';
  69. for($i=$start;$i if(intval($i) == intval($current_page))
  70. $page_num_string .= ''.$i.'';
  71. else
  72. $page_num_string .= ''.$i.'';
  73. }
  74. /* 上下翻页 */
  75. $prev_page = (intval($current_page-1)>0)?intval($current_page-1):0;
  76. $next_page = (intval($current_page) if(!empty($up_down_class))
  77. $up_down_class_str = ' class="'.$up_down_class.'"';
  78. else
  79. $up_down_class_str = '';
  80. $page_up_string = '';
  81. if(intval($prev_page) > 0)
  82. $page_up_string = '';
  83. else
  84. $page_up_string = '上一页';
  85. $page_down_string = '';
  86. if(intval($next_page) > 0)
  87. $page_down_string .= '下一页';
  88. else
  89. $page_down_string .= '下一页';
  90. $page_up_string を返します。 $page_num_string 。 $page_down_string;
  91. }
复制代


ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!