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->Fields['userip'] = $this->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->Fields['body2'] = $this->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->dsql->ExecuteNoneQuery("Update `dede_archives` SET ismake=1 WHERE id='".$this->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->TotalPage > 1) { <br>
//用正则匹配把分页符去掉 <br>
$this->Fields['body2'] = preg_replace('/# p#副标题# e#/U', '',$this->Fields['body2']); <br>
$this->SplitFields = explode("#p2222#",$this->Fields['body2']); <br>
$this->Fields['tmptitle'] = (emptyempty($this->Fields['tmptitle']) ? $this->Fields['title'] : $this->Fields['tmptitle']); <br>
$this->Fields['title'] = $this->Fields['tmptitle']; <br>
$this->TotalPage = count($this->SplitFields); <br>
$this->Fields['totalpage'] = $this->TotalPage; <br>
$TRUEfilenameall = $this->GetTruePath().$fileFirst."_all.".$this->ShortName; <br>
$this->ParseDMFields(1,0); <br>
$this->dtp->SaveTo($TRUEfilenameall); <br><br>
if($cfg_remote_site=='Y' && $isremote == 1) <br>
{ <br><br>
//分析远程文件路径 <br>
$remotefile = str_replace(DEDEROOT, '', $TRUEfilename); <br>
$localfile = '..'.$remotefile; <br>
//创建远程文件夹 <br>
$remotedir = preg_replace("#[^\/]*\.html#", '', $remotefile); <br>
$this->ftp->rmkdir($remotedir); <br>
$this->ftp->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 = "<li><a>共".$totalPage."页: </a></li>"; <br>
$PageList = ""; <br>
$nPage = $nowPage-1; <br>
$lPage = $nowPage+1; <br>
if($nowPage==1) <br>
{ <br>
$PageList.="<a href='javascript:void(0);'><</a>"; <br>
} <br>
else <br>
{ <br>
if($nPage==1) <br>
{ <br>
$PageList.="<a href='".$this->NameFirst.".".$this->ShortName."' target='_self'><</a>"; <br>
} <br>
else <br>
{ <br>
$PageList.="<a href='".$this->NameFirst."_".$nPage.".".$this->ShortName."' target='_self'><</a>"; <br>
} <br>
} <br>
for($i=1;$i<=$totalPage;$i++) <br>
{ <br>
if($i==1) <br>
{ <br>
if($nowPage!=1) <br>
{ <br>
$PageList.="<a href='".$this->NameFirst.".".$this->ShortName."' target='_self'>1</a>"; <br>
} <br>
else <br>
{ <br>
$PageList.="<a class=\"here\" href='javascript:void(0);' target='_self'>1</a>"; <br>
} <br>
} <br>
else <br>
{ <br>
$n = $i; <br>
if($nowPage!=$i) <br>
{ <br>
$PageList.="<a href='".$this->NameFirst."_".$i.".".$this->ShortName."' target='_self'>".$n."</a>"; <br>
} <br>
else <br>
{ <br>
$PageList.="<a class=\"here\" href='javascript:void(0);' target='_self'>{$n}</a>"; <br>
} <br>
} <br>
} <br>
if($lPage <= $totalPage) <br>
{ <br>
$PageList.="<a href='".$this->NameFirst."_".$lPage.".".$this->ShortName."' target='_self'>></a>"; <br>
} <br>
else <br>
{ <br>
$PageList.= "<a href='javascript:void(0);'>></a>"; <br>
} <br>
$PageList.= "<a href='".$this->NameFirst."_all.".$this->ShortName."'>阅读全文</a>"; <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.= "<a href='".$this->NameFirst."_all.".$this->ShortName."'>阅读全文</a>";</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]