内容页分页代码,分页代码
内容页分页代码,分页代码
在使用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参数
以上仅供参考,具体还要根据自己具体项目来调整

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
