爱帮网为大家介绍Dede5.7调用指定id文章的方法

 

有时候我们需要用到特定的一些文章作为我们热推的文章,那么我们在dedecms中,如何调用指定的ID文章了,也许有人会说可以使用dedecms

 

的flag属性,当然可以,但是有时候,我们不必用那么多属性,百度,也许我想哪篇就是哪篇这样是否会好些了,我们可以使用下面的方法。 

{dede:arclist idlist='13' limit='0,1' infolen='60'} 

<span class="ts"><a href="[field:arcurl/]" target="_blank">[field:title/]</a></span>

<span class="tsj">[field:infos/]<a href="[field:arcurl/]" target="_blank" style="color:Red;">[详细]</a></span>

{/dede:arclist}

使用idlist直接调用指定的ID这样的方法,百度,也是比较好的。

官方给与的说明是:idlist =” 提取特定文档(文档ID)。这个很不错,也比较简单和实用。

网络给与的dedecms调用指定id文章的方法:

方法一:

找到:include\inc_arcpart_view.php文件,在里面找到第function ParseTemplet();这一个函数里面的

代码如下:

 

〔 

$this->dtp->Assign($tagid, 

$this->GetArcList($typeid,$ctag->GetAtt("row"),$ctag->GetAtt("col"), 

$titlelen,$infolen,$ctag->GetAtt("imgwidth"),$ctag->GetAtt("imgheight"), 

$ctag->GetAtt("type"),$orderby,$ctag->GetAtt("keyword"),$innertext, 

$ctag->GetAtt("tablewidth"),0,"",$channelid,$ctag->GetAtt("limit"),$ctag->GetAtt("att"), 

$ctag->GetAtt("orderway"),$ctag->GetAtt("subday"),$autopartid,$ctag->GetAtt("ismember") 

将里面的红色的0改为$ctag->GetAtt(‘arcid’),就行了

 

然后到incclude\inc\inc_fun_spgetarclist.php文件里面找到

 

〔if($arcid!=0) $orwhere .= " And arc.ID<>'$arcid' ";〕 

将这一句改为:if($arcid!=0) $orwhere .= " And arc.ID='$arcid' "; 

if($arcid==0) $orwhere .= " And arc.ID<>'$arcid' ";

 

代码如下:

{dede:arclist arcid='13' row='5' col='1' titlelen='24' } 

<table cellspacing='2' cellpadding='2'> 

<tr> 

<td>[field:title/] 

[field:info/]</td> 

</tr> 

</table> 

{/dede:arclist}

这样就只会调用到一个ID为13的文章,即始ROW设为5也没有用,因为从数据库里面只提出一条记录来,

但是现在还不能解析HTML语法,搜狗搜索,提出来的文章没有版式,下次改进。

方法二:

刚一开始没有仔细看论坛,所以自已写出这样的方法,其实大可不必按以上的方法做,可以借助强大的LOOP来实现这一种需求,现将个人方法写在

 

下面,希望对需要的人有帮助;

在首页模板里面加入如下代码:

 

代码如下:

{dede:loop table='dede_addonarticle' sort='aid' row='8' if='aid=50'} 

[field:body/] 

<hr> 

[field:body function="Html2Text(cn_substr('@me',200))" /] 

{/dede:loop}

注意下面的这一行:

{dede:loop table=’dede_addonarticle’ sort=’aid’ row=’8′ if=’aid=50′}

其中有一个aid=50代表要取文章列表的ID号为50的文章,

table=’dede_addonarticle’ 为所存文章的表

其中中间的这一行最重要,

[field:body function="Html2Text(cn_substr('@me',200))" /]

这一句有多种调用方式:

如:[field:body/]将得到文章所有的内容,不过滤HTML标记

[field:body function="(cn_substr('@me',200))" /]

只取内容的前200个字符

[field:body function="Html2Text(cn_substr('@me',200))" /]

取前200个字符并把HTML标记过滤

dedecms调用指定id文章的方法方法三:

你要那篇文章应该知道那篇文章的id,这点应该没有疑问吧

那就可以搞定了,xx就是文章的id,得到文章标题

{dede:global runphp="yes"} 

global $dsql; 

$row=$dsql->getOne("select title from web_archives where id=xxx"); 

@me=$row["title"]; 

{/dede:global} 

  

得到文章的内容 

{dede:global runphp="yes"} 

global $dsql; 

$row=$dsql->getOne("select body from web_addonarticle where aid=xxx"); 

@me=$row["body"]; 

{/dede:global}

选择自己实用的方法,对自己的开发有较大的好处哦。