thinkPHP实现文章上一篇和下一篇,织梦DEDECMS中增加父栏目调用
分类:web前端

方法很简单,也是最懒的方法,把关键之处恢复为升级之前的,需要修改两处。

关键字描述:地址 文档 当前 获取 DEDECMS 2007 教程 方法

因为本人需要,自己就动手修改了其中代码,拿来分享,能用到的朋友可以借鉴一下!
includeinc_typelink.php
1、在这段代码后(大概263行)
if($reID==0 && $typeid>0){
$dbrow = $this->dsql->GetOne("Select reID From dede_arctype where ID='$typeid' ");
if(is_array($dbrow)) $reID = $dbrow['reID'];
}
增加
// 新增代码
if($reID>0){
$dbrow = $this->dsql->GetOne("Select reID From dede_arctype where ID='$reID'");
if(is_array($dbrow)) $parentID = $dbrow['reID'];
}
// 新增代码结束结束
2、然后在以下代码后:
else if($typetype=="self"){
$sql = "Select ID,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl From dede_arctype where reID='$reID' And ishidden<>1 order by sortrank asc limit 0,$row";
}
增加
else if($typetype=="parent"){ //新增代码 获得上级栏目
$sql = "Select ID,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl From dede_arctype where reID='$parentID' And ishidden<>1 order by sortrank asc limit 0,$row";
}
//新增代码结束 获得上级栏目
3、修改下面一句代码
if($row['ID']=="$typeid" && $myinnertext != ''){
修改为:
if(($row['ID']=="$typeid" || $row['ID']=="$reID" || $row['ID']=="$parentID") && $myinnertext != ''){
经过3个步骤的修改
可以实现2个功能:
1、调用父级栏目(上级),对于栏目分级太深的很有用
方法:
{dede:channel type='parent'}{dede:channel}
2、可以调用currentstyle,对于栏目分级太深,还想改变当前栏目样式的很有用!

分享一个在thinkphp框架实现文章上一篇和下一篇的方法,比较实用,可以解决ID不连续的问题。

第一处:

  我是在DEDECMS2007下做的,不知道这篇文章是否多余,DEDECMS调用很方便,但是我找了很久没有
找到调用当前文档的方法,故做了以下教程:DEDECMS 获取当前文档地址。

实现上一篇

修改dede/inc/inc_archives_functions.php

修改方法如下:

$pre=$m->where('id>"'.$_GET["news"].'"')->limit('1')->select();
$this->assign('pre',$pre);

原为:

修改include/inc_archives_view.php

实现下一篇
$next=$m->where('id<"'.$_GET["news"].'"')->order('id desc')->limit('1')->select();
$this->assign('next',$next);

复制代码代码如下:
//更新上下篇文章
if($cfg_up_prenext=='Y' && !empty($typeid))
{
$preRow = $arc->dsql->GetOne("Select ID From `{$arc->MainTable}` where ID".($aid+10)." And arcrank>-1 And typeid='$typeid' order by ID desc");
$nextRow = $arc->dsql->GetOne("Select ID From `{$arc->MainTable}` where ID".($aid-10)." And arcrank>-1 And typeid='$typeid' order by ID asc");
if(is_array($preRow)){
$arc = new Archives($preRow['ID']);
$arc->MakeHtml();
}
if(is_array($nextRow)){
$arc = new Archives($nextRow['ID']);
$arc->MakeHtml();
}
}

找到

 

改为:

//--------------------------
//获取上一篇,下一篇链接
//--------------------------
function GetPreNext($gtype='')
{
$rs = "";
if(count($this->PreNext)<2)
{

调用数据

复制代码代码如下:
//更新上下篇文章
if($cfg_up_prenext=='Y' && !empty($typeid))
{
$preRow = $arc->dsql->GetOne("Select ID From `{$arc->MainTable}` where ID-1 And typeid='$typeid' order by ID desc");
$nextRow = $arc->dsql->GetOne("Select ID From `{$arc->MainTable}` where ID-1 And typeid='$typeid' order by ID asc");
if(is_array($preRow)){
$arc = new Archives($preRow['ID']);
$arc->MakeHtml();
}
if(is_array($nextRow)){
$arc = new Archives($nextRow['ID']);
$arc->MakeHtml();
}
}

$aid = $this->ArcID;
$next = " xkzzz_archives.ID>'$aid' And xkzzz_archives.arcrank>-1 order by xkzzz_archives.ID asc ";
$pre = " xkzzz_archives.ID-1 order by xkzzz_archives.ID desc ";
$query = "Select xkzzz_archives.ID,xkzzz_archives.title,
xkzzz_archives.typeid,xkzzz_archives.ismake,xkzzz_archives.senddate,
xkzzz_archives.arcrank,xkzzz_archives.money,
xkzzz_arctype.typedir,xkzzz_arctype.typename,xkzzz_arctype.namerule,xkzzz_arctype.namerule2,
xkzzz_arctype.ispart,
xkzzz_arctype.moresite,xkzzz_arctype.siteurl
from xkzzz_archives left join xkzzz_arctype on xkzzz_archives.typeid=xkzzz_arctype.ID
where ";
$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'],true,$preRow['siteurl']);
$this->PreNext['pre'] = "上一篇:{$preRow['title']} ";
}
else{
$this->PreNext['pre'] = "上一篇:没有了 ";
}
if(is_array($nextRow)){
$mlink = GetFileUrl($nextRow['ID'],$nextRow['typeid'],$nextRow['senddate'],
$nextRow['title'],$nextRow['ismake'],
$nextRow['arcrank'],$nextRow['namerule'],$nextRow['typedir'],
$nextRow['money'],true,$nextRow['siteurl']);
$this->PreNext['next'] = "下一篇:{$nextRow['title']} ";
}
else{
$this->PreNext['next'] = "下一篇:没有了 ";
}
}

<div class="pre_next">
<volist name="pre" id="pre">
<p>上一篇:<a href=";
</volist>

脚本之家注释: 其实主要是修改了sql语句

if($gtype=='pre'){
上一页12 3 下一页

<volist name="front" id="front">
<p>下一篇:<a href=";
</volist>

原来的:

</div>

复制代码代码如下:
$preRow = $arc->dsql->GetOne("Select ID From `{$arc->MainTable}` where ID".($aid+10)." And arcrank>-1 And typeid='$typeid' order by ID desc");
$nextRow = $arc->dsql->GetOne("Select ID From `{$arc->MainTable}` where ID".($aid-10)." And arcrank>-1 And typeid='$typeid' order by ID asc");

 

现在的

判断功能的实现

复制代码代码如下:
$preRow = $arc->dsql->GetOne("Select ID From `{$arc->MainTable}` where ID-1 And typeid='$typeid' order by ID desc");
$nextRow = $arc->dsql->GetOne("Select ID From `{$arc->MainTable}` where ID-1 And typeid='$typeid' order by ID asc");

$p=!$pre?'没有了':'.__URL__.'/cm/'.$pre['nid'].'"<'.$pre['title'].'';
$this->assign('pre',$p);  

就是将And ID>".($aid+10)." 与And ID>".($aid-10)." 去掉了,为什么id不能大于10呢。如果对于栏目比较多的,肯定不行

第二处:

修改include/inc_archives_view.php

原为:

复制代码代码如下:
//--------------------------
//获取上一篇,下一篇链接
//--------------------------
function GetPreNext($gtype='')
{
$rs = "";
if(count($this->PreNext)<2)
{

$aid = $this->ArcID;
$idmax = $this->ArcID+10;
$idmin = $this->ArcID-10;
$next = " arc.ID>'$aid' And arc.ID-1 And typeid='{$this->Fields['typeid']}' order by arc.ID asc ";
$pre = " arc.ID>'$idmin' And arc.ID-1 And typeid='{$this->Fields['typeid']}' order by arc.ID desc ";
$query = "Select arc.ID,arc.title,arc.shorttitle,
arc.typeid,arc.ismake,arc.senddate,arc.arcrank,arc.money,
t.typedir,t.typename,t.namerule,t.namerule2,t.ispart,
t.moresite,t.siteurl
from `{$this->MainTable}` arc left join dede_arctype t on arc.typeid=t.ID
where ";
$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'],true,$preRow['siteurl']);
$this->PreNext['pre'] = "上一篇:{$preRow['title']} ";
}
else{
$this->PreNext['pre'] = "上一篇:没有了 ";
}
if(is_array($nextRow))
{
$mlink = GetFileUrl($nextRow['ID'],$nextRow['typeid'],$nextRow['senddate'],$nextRow['title'],$nextRow['ismake'],$nextRow['arcrank'],$nextRow['namerule'],$nextRow['typedir'],$nextRow['money'],true,$nextRow['siteurl']);
$this->PreNext['next'] = "下一篇:{$nextRow['title']} ";
}
else{
$this->PreNext['next'] = "下一篇:没有了 ";
}
}

if($gtype=='pre'){
$rs = $this->PreNext['pre'];
}
else if($gtype=='next'){
$rs = $this->PreNext['next'];
}
else{
$rs = $this->PreNext['pre']."   ".$this->PreNext['next'];
}

return $rs;
}

改为:

复制代码代码如下:
//--------------------------
//获取上一篇,下一篇链接
//--------------------------
function GetPreNext($gtype='')
{
$rs = "";
if(count($this->PreNext)<2)
{

$aid = $this->ArcID;
$idmax = $this->ArcID+10;
$idmin = $this->ArcID-10;
$next = " arc.ID>'$aid' And arc.arcrank>-1 And typeid='{$this->Fields['typeid']}' order by arc.ID asc ";
$pre = " arc.ID-1 And typeid='{$this->Fields['typeid']}' order by arc.ID desc ";
$query = "Select arc.ID,arc.title,arc.shorttitle,
arc.typeid,arc.ismake,arc.senddate,arc.arcrank,arc.money,
t.typedir,t.typename,t.namerule,t.namerule2,t.ispart,
t.moresite,t.siteurl
from `{$this->MainTable}` arc left join dede_arctype t on arc.typeid=t.ID
where ";
$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'],true,$preRow['siteurl']);
$this->PreNext['pre'] = "上一篇:{$preRow['title']} ";
}
else{
$this->PreNext['pre'] = "上一篇:没有了 ";
}
if(is_array($nextRow))
{
$mlink = GetFileUrl($nextRow['ID'],$nextRow['typeid'],$nextRow['senddate'],$nextRow['title'],$nextRow['ismake'],$nextRow['arcrank'],$nextRow['namerule'],$nextRow['typedir'],$nextRow['money'],true,$nextRow['siteurl']);
$this->PreNext['next'] = "下一篇:{$nextRow['title']} ";
}
else{
$this->PreNext['next'] = "下一篇:没有了 ";
}
}

if($gtype=='pre'){
$rs = $this->PreNext['pre'];
}
else if($gtype=='next'){
$rs = $this->PreNext['next'];
}
else{
$rs = $this->PreNext['pre']."   ".$this->PreNext['next'];
}

return $rs;
}

改好的文件覆盖上传即可。

当然这里也是修改的sql语句

复制代码代码如下:
$next = " arc.ID>'$aid' And arc.arcrank>-1 And typeid='{$this->Fields['typeid']}' order by arc.ID asc ";
$pre = " arc.ID-1 And typeid='{$this->Fields['typeid']}' order by arc.ID desc ";

因为可能版本不同,不建议直接全部复制,只需要替换下sql语句即可。要不容易出现错误。

本文由10bet手机官网发布于web前端,转载请注明出处:thinkPHP实现文章上一篇和下一篇,织梦DEDECMS中增加父栏目调用

上一篇:7生成首页提示404错误解决办法,dedecms友情链接中去掉织梦链投放修改方法 下一篇:没有了
猜你喜欢
热门排行
精彩图文