分页类——尾部页码导航
<?php /** * 生成Comment的尾部分页导航 * @author 李俊 * */ class cmtTail{ private $currentPage; private $totalPage; /** * 生成页码导航--总控函数 * @param string $currentPage 当前页码 * @param string $totalPage 总页数 * @throws Exception 页码小于1将会抛出异常 * @return string */ function __do($currentPage, $totalPage) { $this->currentPage=$currentPage; $this->totalPage=$totalPage; if($this->totalPage<=10){//总页数小于等于10页 if($this->currentPage==1){//当前页是第一页 $str='上一页'.$this->currentTag(); for ($i = 2; $i <= $this->totalPage; $i++) { $str=$str.$this->commonTag($i); } $str=$str.$this->next(); }elseif ($this->currentPage==$this->totalPage){//已跳至最后一页 $str=$this->up(); for ($i = 1; $i <= $this->totalPage-1; $i++) { $str=$str.$this->commonTag($i); } $str=$str.$this->currentTag(); $str=$str.$this->next(); }else{ $str=$this->up(); for($i=1; $i<$this->currentPage; $i++){ $str=$str.$this->commonTag($i); } $str=$str.$this->currentTag();//生成当前页标签 for ($i = $this->currentPage+1; $i <= $this->totalPage; $i++) { $str=$str.$this->commonTag($i); } $str=$str.$this->next(); } }elseif ($this->totalPage>10){//页码大于10 if($this->currentPage==1){//8+2 $str='上一页'.$this->currentTag(); for ($i = 2; $i <= 8; $i++) { $str=$str.$this->commonTag($i); } $str=$str.'...';//添加省略号 $str=$str.$this->commonTag($this->totalPage-1); $str=$str.$this->commonTag($this->totalPage); }elseif($this->currentPage==$this->totalPage) {//当前为最后一页 $str=$this->up(); $str=$str.$this->commonTag(1); $str=$str.'...';//添加省略号 for ($i = $this->totalPage-6; $i < $this->totalPage; $i++) { $str=$str.$this->commonTag($i); } $str=$str.$this->currentTag(); $str=$str.$this->next(); }else { if ($this->currentPage<6) { $str=$this->up(); for ($i = 1; $i < $this->currentPage; $i++) { $str=$str.$this->commonTag($i); } $str=$str.$this->currentTag(); for ($i = $this->currentPage+1; $i <= 7; $i++) { $str=$str.$this->commonTag($i); } $str=$str.'...';//添加省略号 $str=$str.$this->commonTag($this->totalPage); $str=$str.$this->next(); }else { if ($this->currentPage>=$this->totalPage-4) { $str=$this->up(); $str=$str.$this->commonTag(1); $str=$str.'...';//添加省略号 for ($i = $this->totalPage-6; $i < $this->currentPage; $i++) { $str=$str.$this->commonTag($i); } $str=$str.$this->currentTag(); for ($i = $this->currentPage+1; $i <= $this->totalPage; $i++) { $str=$str.$this->commonTag($i); } $str=$str.$this->next(); }elseif ($this->currentPage<$this->totalPage-4){//1+5+1 $str=$this->up(); $str=$str.$this->commonTag(1); $str=$str.'...';//添加省略号 $str=$str.$this->commonTag($this->currentPage-2); $str=$str.$this->commonTag($this->currentPage-1); $str=$str.$this->currentTag(); $str=$str.$this->commonTag($this->currentPage+1); $str=$str.$this->commonTag($this->currentPage+2); $str=$str.'...';//添加省略号 $str=$str.$this->commonTag($this->totalPage); $str=$str.$this->next(); } }; } }elseif ($this->totalPage<=0){ throw new Exception("页面不可能小于1"); } return $str; } /** * 一般标签 * @param int $param 页码 * @return string */ function commonTag($param) { return '<a page="'.$param.'">'.$param.'</a>'; } /** * 生成当前页标签 * @param int $param 页码 * @return string */ function currentTag() { return '<strong id="on">'.$this->currentPage.'</strong>'; } /** * 生成下一页标签 * @param int $param 下一页页码 * @return string */ function next() { if ($this->currentPage==$this->totalPage) { return '下一页'; } return '<a page="'.($this->currentPage+1).'">下一页</a>'; } /** * 生成上一页标签 * @param int $param 上一页页码 * @return string */ function up() { if ($this->currentPage==1){ return '上一页'; }else{ return '<a page="'.($this->currentPage-1).'">上一页</a>'; } } /** * 实例化cmtTail, * 功能:生成Comment的尾部分页导航 * @param string $currentPage 当前页码 * @param string $totalPage 总页数 * @return string 返回html标签字符串 */ static function GO($currentPage, $totalPage) { $p=new cmtTail(); return $p->__do($currentPage, $totalPage); } }
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
刺客信條陰影:貝殼謎語解決方案
1 週前ByDDD
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

SublimeText3漢化版
中文版,非常好用

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。