织梦文章内容页分别调用上一篇下一篇链接与标题!

今天在给客户做网站建设的时候,客户要求在文章内容页分别调用上一篇下一篇文章的链接与标题,可能有些人并不理解这样做的用意,但客户之前用的是Wordpress,熟悉WP的人或许都知道WP的文章内容页面头部会有两条link代码指向了上一篇下一篇文章的链接与标题,这样做的目的第一可以传递权重,第二则是可以使文章快速的被搜索引擎抓取,而织梦则没有这样的功能,因此我们需要对include文件夹中的文件适当修改以达到织梦文章内容页分别调用上一篇下一篇链接与标题的目的.

织梦文章内容页分别调用上一篇下一篇链接与标题
织梦文章内容页分别调用上一篇下一篇链接与标题

首先打开织梦网站根目录下include文件夹,寻找一个名为arc.archives.class.php的文件,使用DW或Notepad++之类的专业代码编辑器进行编辑,Ctrl+C寻找 “上一篇”,大约在794行位置,将以下代码

function GetPreNext($gtype='')
    {
        $rs = '';
        if(count($this->PreNext)<2)
        {
            $aid = $this->ArcID;
            $preR =  $this->dsql->GetOne("Select id From `#@__arctiny` where id<$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id desc");
            $nextR = $this->dsql->GetOne("Select id From `#@__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 `#@__archives` arc left join #@__arctype t on arc.typeid=t.id  ";
            $nextRow = $this->dsql->GetOne($query.$next);
            $preRow = $this->dsql->GetOne($query.$pre);
            if(is_array($preRow))
            {
                if ( defined('DEDEMOB') )
                {
                    $mlink = 'view.php?aid='.$preRow['id'];
                } else {
                    $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']}\" alt=\"{$preRow['title']}\"/></a> ";
            }
            else
            {
                $this->PreNext['pre'] = "上一篇:没有了 ";
                $this->PreNext['preimg'] ="<img src=\"/templets/default/images/nophoto.jpg\" alt=\"对不起,没有上一图集了!\"/>";
            }
            if(is_array($nextRow))
            {
                if ( defined('DEDEMOB') )
                {
                    $mlink = 'view.php?aid='.$preRow['id'];
                } else {
                    $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']}\" alt=\"{$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>";
            }
        }
        if($gtype=='pre')
        {
            $rs =  $this->PreNext['pre'];
        }
        else if($gtype=='preimg'){

            $rs =  $this->PreNext['preimg'];
        }
        else if($gtype=='next')
        {
            $rs =  $this->PreNext['next'];
        }
        else if($gtype=='nextimg'){

            $rs =  $this->PreNext['nextimg'];
        }
        else
        {
            $rs =  $this->PreNext['pre']." &nbsp; ".$this->PreNext['next'];
        }
        return $rs;
    }

替换为:

//调用单个上一篇下一篇文章
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;
}

保存后在相应的织梦文章内容模板中在合适的位置进行调用:

上一篇:
<a href="{dede:prenext get='nexturl'/}" target="_blank">{dede:prenext get='nextname'/}</a>
下一篇:<a href="{dede:prenext get='preurl'/}" target="_blank">{dede:prenext get='prename'/}</a>

当然你也可以像WP文章内容页一样在头部进行调用:

<link rel="prev" title="{dede:prenext get='nextname'/}" href="{dede:prenext get='nexturl'/}" />
<link rel="next" title="{dede:prenext get='prename'/}" href="{dede:prenext get='preurl'/}" />

通过在文章内容页分别调用上一篇下一篇链接与标题,可以更灵活的使用织梦这一功能,并且可以在头部调用上一篇下一篇链接,通过link标签从而使得搜索引擎更好的抓取网站文章内容,达到秒收合理分配权重的作用,因此还是非常有必要的.

未经允许不得转载:西德SEO » 织梦文章内容页分别调用上一篇下一篇链接与标题!

打赏

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏