织梦获取上一页下一页标题 链接单独调用
织梦默认的上一篇,下一篇调用标签是:{dede:prenext get='pre'/} {dede:prenext get='next'/},有的情况加 我们只想要单独的链接和标题那该怎么办呢!接下来Test玩站网教大家方法.
第一步:打开/include/arc.archives.class.php文件
找到:
/**
* 获取上一篇,下一篇链接
*
* @access public
* @param string $gtype 获取类型
* pre:上一篇 preimg:上一篇图片 next:下一篇 nextimg:下一篇图片
* @return string
*/
大概在795行左右
替换代码:
/**
* 获取上一篇,下一篇链接
*
* @access public
* @param string $gtype 获取类型
* pre:上一篇 preimg:上一篇图片 next:下一篇 nextimg:下一篇图片
* @return string
*/
function GetPreNext($gtype='')
{
$rs = '';
if(count($this->PreNext)<2)
{
$aid = $this->ArcID;
$preR = $this->dsql->GetOne("Select id From `dede_arctiny` where id<$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id desc");
$nextR = $this->dsql->GetOne("Select id From `dede_arctiny` where id>$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id asc");
$next = (is_array($nextR) ? " where arc.id={$nextR['id']} " : ' where 1>2 ');
$pre = (is_array($preR) ? " where arc.id={$preR['id']} " : ' where 1>2 ');
$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 `dede_archives` arc left join dede_arctype t on arc.typeid=t.id ";
$nextRow = $this->dsql->GetOne($query.$next);
$preRow = $this->dsql->GetOne($query.$pre);
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['next'] = "上一篇:<a href='$mlink'>{$preRow['title']}</a> ";
$this->PreNext['nexturl'] = "$mlink"; //上一篇链接地址
$this->PreNext['nextname'] = "{$preRow['title']}"; //上一篇文章标题
$this->PreNext['prewap'] = "<a href=\"view.php?aid={$preRow['id']}\" class=\"pg_a-son fl\" data-ignore=\"true\">上一条</a> ";
$this->PreNext['nextimg'] = "<a href='$mlink'><img src=\"{$preRow['litpic']}\" alt=\"{$preRow['title']}\"/></a> ";
}
else
{
$this->PreNext['next'] = "上一篇:没有了 ";
$this->PreNext['nexturl'] = ""; //上一篇链接地址
$this->PreNext['prewap'] = "<a href=\"javascript:;\" class=\"pg_a-son fl\" data-ignore=\"true\">没有了</a> ";
$this->PreNext['nextimg'] ="<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['pre'] = "下一篇:<a href='$mlink'>{$nextRow['title']}</a> ";
$this->PreNext['preurl'] = "$mlink"; //上一篇链接地址
$this->PreNext['prename'] = "{$nextRow['title']}"; //上一篇文章标题
$this->PreNext['nextwap'] = "<a href=\"view.php?aid={$nextRow['id']}\" class=\"pg_a-son fr\" data-ignore=\"true\">下一条</a> ";
$this->PreNext['preimg'] = "<a href='$mlink'><img src=\"{$nextRow['litpic']}\" alt=\"{$nextRow['title']}\"/></a> ";
}
else
{
$this->PreNext['pre'] = "下一篇:没有了 ";
$this->PreNext['preurl'] = ""; //上一篇链接地址
$this->PreNext['nextwap'] = "<a href=\"javascript:;\" class=\"pg_a-son fr\" data-ignore=\"true\">没有了</a> ";
$this->PreNext['preimg'] ="<a href='javascript:void(0)' alt=\"\"><img src=\"/templets/default/images/nophoto.jpg\" alt=\"对不起,没有下一图集了!\"/></a>";
}
}
if($gtype=='pre')
{
$rs = $this->PreNext['pre'];
}
else if($gtype=='prewap'){
$rs = $this->PreNext['prewap'];
}
else if($gtype=='preimg'){
$rs = $this->PreNext['preimg'];
}
else if($gtype=='next')
{
$rs = $this->PreNext['next'];
}
else if($gtype=='nextwap')
{
$rs = $this->PreNext['nextwap'];
}
else if($gtype=='nextimg'){
$rs = $this->PreNext['nextimg'];
}
else if($gtype=='preurl'){
$rs = $this->PreNext['preurl'];
}
else if($gtype=='prename'){
$rs = $this->PreNext['prename'];
}
else if($gtype=='nexturl'){
$rs = $this->PreNext['nexturl'];
}
else if($gtype=='nextname'){
$rs = $this->PreNext['nextname'];
}
else
{
$rs = $this->PreNext['pre']." ".$this->PreNext['next'];
}
return $rs;
}
第二步:文件替换好了 ,那就可以调用的了,调用标签如下:
上一篇标题:{dede:prenext get='prename'/} 上一篇链接:{dede:prenext get='preurl'/}
下一篇标题:{dede:prenext get='nextname'/} 下一篇链接:{dede:prenext get='nexturl'/}
注:因为调用顺序是按发布时间更新的,有人问为啥下一篇链接用preurl,这个不做解释了,自己调用一下就明白了!
一个自己的Test玩站网