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

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

1、修改文件:

/include/arc.archives.class.php

然后我们找到:

$this->Fields['userip'] = $this->addTableRow['userip'];

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

$this->Fields['body2'] = $this->addTableRow['body'];

然后我们再查找到:

$this->dsql->ExecuteNoneQuery("Update `#@__archives` SET ismake=1 WHERE id='".$this->ArcID."'");

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

//阅读全文开始
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、获取静态列表分页

查找到:

/**
* 获得静态页面分页列表
*
* @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 上一行添加下面一行代码:

$PageList.= "<a href='".$this->NameFirst."_all.".$this->ShortName."'>阅读全文</a>";

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

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。