Home > Article > Backend Development > Content page pagination code
In the content management system developed using Thinkphp, many things need to be developed by yourself. Of course, content paging also needs to be developed by yourself. Here is the method I compiled based on the information:
1. First, you need to insert page breaks when editing content in the background. The page breaks of different editors are naturally different
2. Then when reading the article content, the content must be divided into multiple arrays according to the page breaks. However, here you need to pass the value of which page the current page is, and read the divided array according to the page number
The code is as follows:
<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开始-->
Note: If you use Thinkphp and configure staticization,
Modify the configuration file 'News:article'=>array('{:module}/{:action}_{art_id}_{p}',0) and add a p parameter
The above is for reference only, it needs to be adjusted according to your specific project
The above introduces the content page paging code, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.