前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >织梦DedeCMS文章内容页面添加阅读更多功能方法

织梦DedeCMS文章内容页面添加阅读更多功能方法

作者头像
老蒋
发布2021-12-27 12:21:55
2.1K0
发布2021-12-27 12:21:55
举报
文章被收录于专栏:老蒋专栏老蒋专栏

一般我们会使用织梦DedeCMS程序搭建内容类型的网站,而且有些内容单篇文章是比较长的。于是我们是不是看到有些网站在教程的内容篇幅中下面添加有【阅读更多】或者类似【阅读全文】的功能。那这个方法是如何实现的呢?这里如果我们也有需要将DEDECMS织梦程序实现文章内容页添加阅读更多功能的话可以效仿下面的办法进行页面处理。

当然,如果我们准备修改页面之前,最好是将页面备份,万一修改错我们还可以去复原。

1、修改文件:

代码语言:javascript
复制
/include/arc.archives.class.php

然后我们找到:

代码语言:javascript
复制
$this->Fields['userip'] = $this->addTableRow['userip'];

这里我们最好通过查询方法进行找到定位。在这个代码下面添加:

代码语言:javascript
复制
$this->Fields['body2'] = $this->addTableRow['body'];

然后我们再查找到:

代码语言:javascript
复制
$this->dsql->ExecuteNoneQuery("Update `#@__archives` SET ismake=1 WHERE id='".$this->ArcID."'");

找到这个代码。然后添加:

代码语言:javascript
复制
//阅读全文开始
if($this->TotalPage > 1) {
//用正则匹配把分页符去掉
$this->Fields['body2'] = preg_replace('/#p#副标题#e#/U', '',$this->Fields['body2']);
$this->SplitFields = explode("#p2222#",$this->Fields['body2']);
$this->Fields['tmptitle'] = (empty($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');
}
}
//阅读全文结束

2、获取静态列表分页

查找到:

代码语言:javascript
复制
/**
* 获得静态页面分页列表
*
* @access public
* @param int $totalPage 总页数
* @param int $nowPage 当前页数
* @param int $aid 文档id
* @return string
*/
function GetPagebreak($totalPage, $nowPage, $aid)
{
if($totalPage==1)
{
return "";
}
//$PageList = "<li><a>共".(www.111cn.net)$totalPage."页: </a></li>";
$PageList = "";
$nPage = $nowPage-1;
$lPage = $nowPage+1;
if($nowPage==1)
{
$PageList.="<a href='javascript:void(0);'><</a>";
}
else
{
if($nPage==1)
{
$PageList.="<a href='".$this->NameFirst.".".$this->ShortName."' target='_self'><</a>";
}
else
{
$PageList.="<a href='".$this->NameFirst."_".$nPage.".".$this->ShortName."' target='_self'><</a>";
}
}
for($i=1;$i<=$totalPage;$i++)
{
if($i==1)
{
if($nowPage!=1)
{
$PageList.="<a href='".$this->NameFirst.".".$this->ShortName."' target='_self'>1</a>";
}
else
{
$PageList.="<a class=\"here\" href='javascript:void(0);' target='_self'>1</a>";
}
}
else
{
$n = $i;
if($nowPage!=$i)
{
$PageList.="<a href='".$this->NameFirst."_".$i.".".$this->ShortName."' target='_self'>".$n."</a>";
}
else
{
$PageList.="<a class=\"here\" href='javascript:void(0);' target='_self'>{$n}</a>";
}
}
}
if($lPage <= $totalPage)
{
$PageList.="<a href='".$this->NameFirst."_".$lPage.".".$this->ShortName."' target='_self'>></a>";
}
else
{
$PageList.= "<a href='javascript:void(0);'>></a>";
}
$PageList.= "<a href='".$this->NameFirst."_all.".$this->ShortName."'>阅读全文</a>";
return $PageList;
}

然后在 return $PageList 上一行添加下面一行代码:

代码语言:javascript
复制
$PageList.= "<a href='".$this->NameFirst."_all.".$this->ShortName."'>阅读全文</a>";

然后我们再看看效果。这里需要注意的是,做好备份,万一实现不了,我们就恢复不要折腾。

本文出处:老蒋部落 » 织梦DedeCMS文章内容页面添加阅读更多功能方法 | 欢迎分享

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-02-10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档