马上飞来 發表於 2024-3-10 00:00:00

dedecms5.7文章二次开发实现阅读全文功能的方法

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        本文实例讲述了dedecms5.7文章二次开发实现阅读全文功能的方法。分享给大家供大家参考。具体分析如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        阅读全文功能其实在很多的流行站点都有的,比如网易,新浪等,随着文章内容的增加,当一个页面有多个分页的时候,就会显示出这个“在本页阅读全文”的链接,点击这个链接之后出现的,将是这篇文章以没有分页出现的型式,那么在dedecms5.7如何在文章内容页添加阅读全文功能呢?</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";'>
        修改文件: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";'>
        注意:做任何修改前都要备份好原文件.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        第一步:打开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";'>
        文件查找://issystem==-1</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        往下 大概 145行 找到:</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="phpcode6" 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";'>
        $this-&gt;Fields['userip'] = $this-&gt;addTableRow['userip'];</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";'>
        在下面一行添加:</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="phpcode7" 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";'>
        $this-&gt;Fields['body2'] = $this-&gt;addTableRow['body'];</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";'>
        第二步查找:</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="phpcode8" 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";'>
        $this-&gt;dsql-&gt;ExecuteNoneQuery("Update `dede_archives` SET ismake=1 WHERE id='".$this-&gt;ArcID."'");</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";'>
        在上一行添加以下代码:<br>
         </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="phpcode9" 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>
        if($this-&gt;TotalPage &gt; 1) { <br>
        //用正则匹配把分页符去掉 <br>
        $this-&gt;Fields['body2'] = preg_replace('/# p#副标题# e#/U', '',$this-&gt;Fields['body2']); <br>
        $this-&gt;SplitFields = explode("#p2222#",$this-&gt;Fields['body2']); <br>
        $this-&gt;Fields['tmptitle'] = (emptyempty($this-&gt;Fields['tmptitle']) ? $this-&gt;Fields['title'] : $this-&gt;Fields['tmptitle']); <br>
        $this-&gt;Fields['title'] = $this-&gt;Fields['tmptitle']; <br>
        $this-&gt;TotalPage = count($this-&gt;SplitFields); <br>
        $this-&gt;Fields['totalpage'] = $this-&gt;TotalPage; <br>
        $TRUEfilenameall = $this-&gt;GetTruePath().$fileFirst."_all.".$this-&gt;ShortName; <br>
        $this-&gt;ParseDMFields(1,0); <br>
        $this-&gt;dtp-&gt;SaveTo($TRUEfilenameall); <br><br>
        if($cfg_remote_site=='Y' &amp;&amp; $isremote == 1) <br>
        { <br><br>
        //分析远程文件路径 <br>
        $remotefile = str_replace(DEDEROOT, '', $TRUEfilename); <br>
        $localfile = '..'.$remotefile; <br>
        //创建远程文件夹 <br>
        $remotedir = preg_replace("#[^\/]*\.html#", '', $remotefile); <br>
        $this-&gt;ftp-&gt;rmkdir($remotedir); <br>
        $this-&gt;ftp-&gt;upload($localfile, $remotefile, 'ascii'); <br>
        }<br>
        } <br>
        //阅读全文结束</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>第三步:查找 获得静态页面分页列表,代码如下:</span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><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="phpcode10" 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>
        * 获得静态页面分页列表 <br>
        * <br>
        * @access public <br>
        * @param int $totalPage 总页数 <br>
        * @param int $nowPage 当前页数 <br>
        * @param int $aid 文档id <br>
        * @return string <br>
        */ <br>
        function GetPagebreak($totalPage, $nowPage, $aid) <br>
        { <br>
        if($totalPage==1) <br>
        { <br>
        return ""; <br>
        } <br>
        //$PageList = "&lt;li&gt;&lt;a&gt;共".$totalPage."页: &lt;/a&gt;&lt;/li&gt;"; <br>
        $PageList = ""; <br>
        $nPage = $nowPage-1; <br>
        $lPage = $nowPage+1; <br>
        if($nowPage==1) <br>
        { <br>
        $PageList.="&lt;a href='javascript:void(0);'&gt;&lt;&lt;/a&gt;"; <br>
        } <br>
        else <br>
        { <br>
        if($nPage==1) <br>
        { <br>
        $PageList.="&lt;a href='".$this-&gt;NameFirst.".".$this-&gt;ShortName."' target='_self'&gt;&lt;&lt;/a&gt;"; <br>
        } <br>
        else <br>
        { <br>
        $PageList.="&lt;a href='".$this-&gt;NameFirst."_".$nPage.".".$this-&gt;ShortName."' target='_self'&gt;&lt;&lt;/a&gt;"; <br>
        } <br>
        } <br>
        for($i=1;$i&lt;=$totalPage;$i++) <br>
        { <br>
        if($i==1) <br>
        { <br>
        if($nowPage!=1) <br>
        { <br>
        $PageList.="&lt;a href='".$this-&gt;NameFirst.".".$this-&gt;ShortName."' target='_self'&gt;1&lt;/a&gt;"; <br>
        } <br>
        else <br>
        { <br>
        $PageList.="&lt;a class=\"here\" href='javascript:void(0);' target='_self'&gt;1&lt;/a&gt;"; <br>
        } <br>
        } <br>
        else <br>
        { <br>
        $n = $i; <br>
        if($nowPage!=$i) <br>
        { <br>
        $PageList.="&lt;a href='".$this-&gt;NameFirst."_".$i.".".$this-&gt;ShortName."' target='_self'&gt;".$n."&lt;/a&gt;"; <br>
        } <br>
        else <br>
        { <br>
        $PageList.="&lt;a class=\"here\" href='javascript:void(0);' target='_self'&gt;{$n}&lt;/a&gt;"; <br>
        } <br>
        } <br>
        } <br>
        if($lPage &lt;= $totalPage) <br>
        { <br>
        $PageList.="&lt;a href='".$this-&gt;NameFirst."_".$lPage.".".$this-&gt;ShortName."' target='_self'&gt;&gt;&lt;/a&gt;"; <br>
        } <br>
        else <br>
        { <br>
        $PageList.= "&lt;a href='javascript:void(0);'&gt;&gt;&lt;/a&gt;"; <br>
        } <br>
        $PageList.= "&lt;a href='".$this-&gt;NameFirst."_all.".$this-&gt;ShortName."'&gt;阅读全文&lt;/a&gt;"; <br>
        return $PageList; <br>
        }</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>也就是在return $PageList 上一行添加了一行代码:</span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><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="phpcode11" 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";'>
        $PageList.= "&lt;a href='".$this-&gt;NameFirst."_all.".$this-&gt;ShortName."'&gt;阅读全文&lt;/a&gt;";</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";'>
        修改完成后,保存文件,更新一下页面就可以看到效果了.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        希望本文所述对大家的dedecms建站有所帮助。</p>
頁: [1]
查看完整版本: dedecms5.7文章二次开发实现阅读全文功能的方法