微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

Dedecms5.7文章二次开发实现阅读全文功能方法分享给大家供大家参考。具体分析如下:

功能其实在很多的流行站点都有的,比如网易,新浪等,随着文章内容增加,当一个页面有多个分页的时候,就会显示出这个“在本页阅读全文”的链接,点击这个链接之后出现的,将是这篇文章以没有分页出现的型式,那么在Dedecms5.7如何在文章内容添加阅读全文功能呢?

用户体验,下面让我们看看,怎么简单现实这个功能.

修改文件:include/arc.archives.class.PHP

修改前都要备份好原文件.

PHP

文件查找://issystem==-1

复制代码
代码如下:
Fields['userip'] = $this->addTableRow['userip'];

添加:

复制代码
代码如下:
Fields['body2'] = $this->addTableRow['body'];

复制代码
代码如下:
dsql->ExecuteNoneQuery("Update `dede_archives` SET ismake=1 WHERE id='".$this->ArcID."'");

添加以下代码:

复制代码
代码如下:
TotalPage > 1) { //用正则匹配把分页符去掉 $this->Fields['body2'] = preg_replace('/# p#副标题# e#/U','',$this->Fields['body2']); $this->SplitFields = explode("#p2222#",$this->Fields['body2']); $this->Fields['tmptitle'] = (emptyempty($this->Fields['tmptitle']) ? $this->Fields['title'] : $this->Fields['tmptitle']); $this->Fields['title'] = $this->Fields['tmptitle']; $this->TotalPage = count($this->SplitFields); $this->Fields['totalpage'] = $this->TotalPage; $TRUEfilenameall = $this->GetTruePath().$fileFirst."_all.".$this->ShortName; $this->ParseDMFields(1,0); $this->dtp->Saveto($TRUEfilenameall); if($cfg_remote_site=='Y' && $isremote == 1) { //分析远程文件路径 $remotefile = str_replace(DEDEROOT,$TRUEfilename); $localfile = '..'.$remotefile; //创建远程文件夹 $remotedir = preg_replace("#[^/]*.html#",$remotefile); $this->ftp->rmkdir($remotedir); $this->ftp->upload($localfile,$remotefile,'ascii'); } } //阅读全文结束

页面分页列表,代码如下:

复制代码
代码如下:
PHP">/** * 获得静态页面分页列表 * * @access public * @param int $totalPage 总页数 * @param int $NowPage 当前页数 * @param int $aid 文档id * @return string */ function GetPagebreak($totalPage,$NowPage,$aid) { if($totalPage==1) { return ""; } //$Pagelist = " 共".$totalPage."页: "; $Pagelist = ""; $nPage = $NowPage-1; $lPage = $NowPage+1; if($NowPage==1) { $Pagelist.="<"; } else { if($nPage==1) { $PageList.="NameFirst.".".$this->ShortName."' target='_self'><"; } else { $PageList.="NameFirst."_".$nPage.".".$this->ShortName."' target='_self'><"; } } for($i=1;$i<=$totalPage;$i++) { if($i==1) { if($nowPage!=1) { $PageList.="NameFirst.".".$this->ShortName."' target='_self'>1"; } else { $Pagelist.="1"; } } else { $n = $i; if($NowPage!=$i) { $Pagelist.="NameFirst."_".$i.".".$this->ShortName."' target='_self'>".$n.""; } else { $Pagelist.="{$n}"; } } } if($lPage <= $totalPage) { $PageList.="NameFirst."_".$lPage.".".$this->ShortName."' target='_self'>>"; } else { $Pagelist.= ">"; } $Pagelist.= "NameFirst."_all.".$this->ShortName."'>阅读全文"; return $Pagelist; }

Pagelist 上一行添加了一行代码:

复制代码
代码如下:
ShortName."'>阅读全文";

修改完成后,保存文件,更新一下页面就可以看到效果了.

Dedecms建站有所帮助。

原文地址:https://www.jb51.cc/dedecms/403866.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

阅读全文

相关推荐