桑塔纳 發表於 2023-12-21 00:00:00

DEDECMS内容页分页过多、过长问题最佳解决方案

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        今天在织梦论坛上看到很多咨询关于分页太多,导致页码导航全部显示而撑破网页或不太美观的问题,当然相信很多用DedeCMS的站长朋友们多少也都遇到这样的问题,如下图所示:</p>
<p align="center" style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <img style="max-width:100%!important;height:auto!important;"title="DEDECMS内容页分页过多、过长问题最佳解决方案" alt="DEDECMS内容页分页过多、过长问题最佳解决方案" src="https://zhuji.jb51.net/uploads/img/202305/215bc44ec9f3908f5edc28d9786a7dc2.jpg"></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        导致页码导航全部显示而撑破网页或不太美观的问题</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
          那么该如何让页码智能显示,每页只固定显示当前页的前后几个呢?仔细想一下其实并不太难,首先我们需要知道解析分页的文件是哪一个,一般情况下dedecms此类文件都会放在include下,用查找的方式找了一下“<strong>上一页&lt;/a&gt;&lt;/li&gt;</strong>”,不用说也知道这是为什么要找它,因为这是分页唯一的代码!很快我们查找到了arc.archives.class.php文件,但是其中有两处,仔细看了一下,第一处是列表页用的,第二处是文章页用的,下边就来解决一下如何智能分页,本人asp学的还可以,php就差多了,在5.1的时候记的有个朋友写过,于是拿出来改了一下,修改方法如下:<br><br>
        打开include/arc.archives.class.php文件</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        dedecms5.1版本<br><br>
        inc_archives_view.php<br><br>
        dedecms 5.5 5.5是<br><br>
        arc.archives.class.php</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        找到GetPagebreakDM //修改的是列表页</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        找到代码:for($i=1;$i&lt;=$totalPage;$i++) (注意:共有两处,上面说了,改第二处,大约813行处,当然两个都可以修改,上面的是动态页面,下面的是静态页面)。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode3" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        $total_list=8; //只显示8个页码 (jb51.net)注<br>
        if($nowPage &gt;= $total_list) {<br>
        $i = $nowPage-4; //显示4页<br>
        $total_list = $nowPage+4; //显示4页<br>
        if($total_list &gt;= $totalPage) $total_list = $totalPage;<br>
        }else{<br>
        $i=1;<br>
        if($total_list &gt;= $totalPage) $total_list = $totalPage;<br>
        }<br>
        for($i;$i&lt;=$total_list;$i++)</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        再将for($i=1;$i&lt;=$totalPage;$i++) 修改成for($i;$i&lt;=$total_list;$i++) <br>
        找到GetPagebreak //修改的是内容页,修改方法同上 <br><br>
        接下来,保存arc.archives.class.php文件并上传。登陆dede后台,找到分页比较多的文章,重新生成HTML,再看一下分页的效果,如下图: </p>
<p align="center" style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <img style="max-width:100%!important;height:auto!important;"title="DEDECMS内容页分页过多、过长问题最佳解决方案" alt="DEDECMS内容页分页过多、过长问题最佳解决方案" src="https://zhuji.jb51.net/uploads/img/202305/500e0e0c14e9253235a2c1a5c22d0111.jpg"></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        看到效果了吧?就是不管有多少页,只显示当前页的前四与后四个页码,以上图为例,现在是第八页,只显示前边到四和后边到十二,赶快试一下吧,注意该方法只适合dedecms5.1、dedecms5.3和5.5哦。</p>
頁: [1]
查看完整版本: DEDECMS内容页分页过多、过长问题最佳解决方案