無需改動tp的page類文件茶宵,只需把輸出模板的html代碼用我這個bootstrap_page_style函數替換即可變成Bootstrap分頁樣式注意:我使用的tp框架為3.2.3蹬跃、Bootstrap 為 v3.3.0 版本笛厦,其他版本大同小異,可以根據這個函數自行修改建车!函數代碼:
/**
* Thinkphp默認分頁樣式轉Bootstrap分頁樣式
* @author H.W.H
* @param string $page_html tp默認輸出的分頁html代碼
* @return string 新的分頁html代碼
*/
function bootstrap_page_style($page_html){
if ($page_html) {
$page_show = str_replace('<div>','<nav><ul class="pagination">',$page_html);
$page_show = str_replace('</div>','</ul></nav>',$page_show);
$page_show = str_replace('<span class="current">','<li class="active"><a>',$page_show);
$page_show = str_replace('</span>','</a></li>',$page_show);
$page_show = str_replace(array('<a class="num"','<a class="prev"','<a class="next"','<a class="end"','<a class="first"'),'<li><a',$page_show);
$page_show = str_replace('</a>','</a></li>',$page_show);
}
return $page_show;
}
css代碼.hwh-page-info a{color: #CCC;}.hwh-page-info a em{font-style: normal;margin: 0 2px;}
使用實例代碼:$Page->lastSuffix = false;//最后一頁不顯示為總頁數
$Page->setConfig('header','<li class="disabled hwh-page-info"><a>共<em>%TOTAL_ROW%</em>條 <em>%NOW_PAGE%</em>/%TOTAL_PAGE%頁</a></li>');
$Page->setConfig('prev','上一頁');
$Page->setConfig('next','下一頁');
$Page->setConfig('last','末頁');
$Page->setConfig('first','首頁');
$Page->setConfig('theme','%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
$page_show = bootstrap_page_style($Page->show());//重點在這里
$this->assign('page_show'=>$page_show);