在DedeCMS中的文章页面的上一篇下一篇链接处增加文章摘要的方法

时间:2021-05-02

DedeCMS系统默认的是在文章的上一篇和下一篇的链接只显示标题,但是有时我们希望显示其他信息,比如文章的摘要。
找到arc.archives.class.php文件,在include目录下面,然后查找“GetPreNext”这个函数,将

$query = "Select arc.id,arc.title,arc.shorttitle,arc.typeid,arc.ismake,arc.senddate,arc.arcrank,arc.money,arc.filename,arc.litpic, t.typedir,t.typename,t.namerule,t.namerule2,t.ispart,t.moresite,t.siteurl,t.sitepath from `jcode_archives` arc left join jcode_arctype t on arc.typeid=t.id ";

  改成:

$query = "Select arc.id,arc.title,arc.shorttitle,arc.typeid,arc.ismake,arc.senddate,arc.arcrank,arc.money,arc.filename,arc.litpic, arc.description,t.typedir,t.typename,t.namerule,t.namerule2,t.ispart,t.moresite,t.siteurl,t.sitepath from `jcode_archives` arc left join jcode_arctype t on arc.typeid=t.id ";

  比较一下其实现在只是多了arc.description,这就是文章的摘要,也称为文章描述。

  需要注意的是这里的jcode_archives和jcode_arctype中的jcode_是我表结构的前缀,你需要将这个前缀改成你自己的。

  现在我们已经将文章描述从数据库里面取出来了。下一步将描述显示在页面上,显示连接文字的代码本来是这样的,你可以通过查找找到,其实就在上面那段代码的附近:

if(is_array($preRow)){$mlink = GetFileUrl($preRow['id'],$preRow['typeid'],$preRow['senddate'],$preRow['title'],$preRow['ismake'],$preRow['arcrank'],$preRow['namerule'],$preRow['typedir'],$preRow['money'],$preRow['filename'],$preRow['moresite'],$preRow['siteurl'],$preRow['sitepath']);$this->PreNext['pre'] = "上一篇:<a href='$mlink'>{$preRow['title']}</a> ";$this->PreNext['preimg'] = "<a href='$mlink'><img src="{$preRow['litpic']}" style="line-height: 25.2px; color: rgb(255, 0, 255);">"{$preRow['title']}"/></a> ";}else{$this->PreNext['pre'] = "上一篇:没有了 "; $this->PreNext['preimg'] ="<img src="/templets/default/images/nophoto.jpg" alt="对不起,没有上一图集了!"/>";}if(is_array($nextRow)){$mlink = GetFileUrl($nextRow['id'],$nextRow['typeid'],$nextRow['senddate'],$nextRow['title'],$nextRow['ismake'],$nextRow['arcrank'],$nextRow['namerule'],$nextRow['typedir'],$nextRow['money'],$nextRow['filename'],$nextRow['moresite'],$nextRow['siteurl'],$nextRow['sitepath']);$this->PreNext['next'] = "下一篇:<a href='$mlink'>{$nextRow['title']}</a> ";$this->PreNext['nextimg'] = "<a href='$mlink'><img src="{$nextRow['litpic']}" style="line-height: 25.2px; color: rgb(255, 0, 255);">"{$nextRow['title']}"/></a> ";}else{$this->PreNext['next'] = "下一篇:没有了 "; $this->PreNext['nextimg'] ="<a href='javascript:void(0)' alt=""><img src="/templets/default/images/nophoto.jpg" alt="对不起,没有下一图集了!"/></a>";}}

  现在为了显示出文章描述,在每一个a标签之后添加一个div div中包含文章描述:

if(is_array($preRow)){$mlink = GetFileUrl($preRow['id'],$preRow['typeid'],$preRow['senddate'],$preRow['title'],$preRow['ismake'],$preRow['arcrank'],$preRow['namerule'],$preRow['typedir'],$preRow['money'],$preRow['filename'],$preRow['moresite'],$preRow['siteurl'],$preRow['sitepath']);$this->PreNext['pre'] = "上一篇:<a href='$mlink'>{$preRow['title']}</a> <div>{$preRow['description']}</div> ";$this->PreNext['preimg'] = "<a href='$mlink'><img src="{$preRow['litpic']}" style="line-height: 25.2px; color: rgb(255, 0, 255);">"{$preRow['title']}"/></a> <div>{$preRow['description']}</div> "; }else{$this->PreNext['pre'] = "上一篇:没有了 ";$this->PreNext['preimg'] ="<img src="/templets/default/images/nophoto.jpg" alt="对不起,没有上一图集了!"/>";}if(is_array($nextRow)){$mlink = GetFileUrl($nextRow['id'],$nextRow['typeid'],$nextRow['senddate'],$nextRow['title'],$nextRow['ismake'],$nextRow['arcrank'],$nextRow['namerule'],$nextRow['typedir'],$nextRow['money'],$nextRow['filename'],$nextRow['moresite'],$nextRow['siteurl'],$nextRow['sitepath']);$this->PreNext['next'] = "下一篇:<a href='$mlink'>{$nextRow['title']}</a> <div>{$preRow['description']}</div> ";$this->PreNext['nextimg'] = "<a href='$mlink'><img src="{$nextRow['litpic']}" style="line-height: 25.2px; color: rgb(255, 0, 255);">"{$nextRow['title']}"/></a> <div>{$preRow['description']}</div> "; }else{$this->PreNext['next'] = "下一篇:没有了 ";$this->PreNext['nextimg'] ="<a href='javascript:void(0)' alt=""><img src="/templets/default/images/nophoto.jpg" alt="对不起,没有下一图集了!"/></a>";}}

  这样做的话能显示文章摘要,但是格式可能会很乱,你可以根据需要增加样式。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章