首页 >php教程 >php手册 >内容页分页代码,分页代码

内容页分页代码,分页代码

WBOY
WBOY原创
2016-06-13 09:17:04992浏览

内容页分页代码,分页代码

在使用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>$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参数

 

 

以上仅供参考,具体还要根据自己具体项目来调整

 

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn