在使用Thinkphp開發的內容管理系統裡面,很多東西都要自己開發,內容分頁當然也是要自己開發的,以下是我根據查資料自己整理的方法:
1、首先是在後台編輯內容的時候需要插入分頁符,不同的編輯器分頁符自然也不同了
2、然後就是讀取文章內容的時候,要根據分頁符號來把內容分割成多個數組然,這裡需要傳值當前是第幾頁,根據頁數來讀取分割後的數組
程式碼如下:
<php> <span>$arr_con</span>=<span>explode</span>('_ueditor_page_break_tag_',<span>$dy</span>['art_content']);<span>//</span><span>分割内容</span> <span>$pagenum</span>=<span>count</span>(<span>$arr_con</span>);<span>//</span><span>计算页数 //根据传值判断当前显示页数</span> <span>if</span>(<span>intval</span>(<span>$_GET</span>['p'])==0<span>){ </span><span>$p</span>=1<span>; }</span><span>else</span><span>{ </span><span>$p</span>=<span>intval</span>(<span>$_GET</span>['p'<span>]); } </span><span>//</span><span>获得当前页的url</span> <span>$url</span> = <span>$_SERVER</span>['REQUEST_URI'].(<span>strpos</span>(<span>$_SERVER</span>['REQUEST_URI'],'?')?'':"?"<span>); </span><span>$parse</span> = <span>parse_url</span>(<span>$url</span><span>); </span><span>if</span>(<span>isset</span>(<span>$parse</span>['query'<span>])) { </span><span>parse_str</span>(<span>$parse</span>['query'],<span>$params</span><span>); </span><span>unset</span>(<span>$params</span>['p'<span>]); </span><span>$url</span> = <span>$parse</span>['path'].'?'.<span>http_build_query</span>(<span>$params</span><span>); } </span><span>//</span><span>有多少页都全部循环出来</span> <span>for</span>(<span>$i</span>=1;<span>$i</span><=<span>$pagenum</span>;<span>$i</span>++<span>){ </span><span>if</span>(<span>$i</span>==<span>$p</span><span>){ </span><span>$show</span>.='<span>['.<span>$i</span>.']</span>'<span>; } </span><span>else</span><span>{ </span><span>$show</span>.='<a href="'.<span>$url</span>.'&p='.<span>$i</span>.'">['.<span>$i</span>.']</a>'<span>; } } </span><span>//</span><span> dump($arr_con);</span> <span>$show</span>=<span>$pagenum</span>==1?'':<span>$show</span>;<span>//</span><span>分页代码显示判断</span> </php><span> {</span><span>$arr_con</span>[<span>$p</span>-1]}<!--这里是刚进入这篇文章显示的数据,数组键值从0开始-->
注意:如果使用的Thinkphp,並且配置了靜態化,
則修改設定檔'News:article'=>array('{:module}/{:action}_{art_id}_{p}',0),加個p參數
以上僅供參考,具體也要根據自己具體項目來調整
以上就介紹了內容頁分頁程式碼,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。