1. 当前位置:站长学院 > 织梦cms教程 >

dedecms 调用指定栏目,指定作者,指定自定义字段

百度知道里看到有人提问,帮写了一个。

 

模板里调用SQL:

1 2 3 4 5 6 {dede:sql sql="select a.id,a.title,a.writer,a.pubdate,a.typeid,b.aid,b.sex from dede_archives a LEFT JOIN dede_addonarticle b on b.aid=a.id where a.typeid='7' and a.writer=~writer~ and b.sex='男' order by a.pubdate desc LIMIT 0,5"}             <li>文章ID:[field:id/]</li>             <li>标题:<a href="[field:id function='GetOneDocUrl(@me)'/]">[field:title/]</a></li>             <li>作者:[field:writer/]</li>             <li>性别:[field:sex/]</li>           {/dede:sql}

 

a.typeid=7   调用ID为7的栏目  如果不需要指定栏目ID  那么你可以把 a.typeid='7' and  删掉

a.writer=~writer~  调用当前文章的作者,调用指定的作者,可以这样写a.writer='admin'  这样就是指定调用admin这个作者的文档

b.sex=男  设置性别,也就是自定义字段。如果你的自定义字段不是sex 那么你只要把sql里的b.sex 改成你的字段,例如 name 改成b.name

LIMIT 0,5  设置要调用的条数,我这里写的是5条,自行修改.

 

指定调用2个栏目的话  可以把where a.typeid='7'  修改为 where a.typeid='7' and a.typeid='8'

这样就指定调用栏目ID 为 7和8的栏目

 

 

 

GetOneDocUrl 函数 放到incluce/extend.func.php 文件中,这个函数是用来调用文档的静态URL的。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 function GetOneDocUrl($aid) {     global $dsql;     include_once(DEDEINC."/channelunit.func.php");     $aid = trim(ereg_replace('[^0-9]','',$aid));       $chRow $dsql->GetOne("Select arc.*,ch.maintable,ch.addtable,ch.issystem From `dede_arctiny` arc left join `dede_channeltype` ch on ch.id=arc.channel where arc.id='$aid' ");       if(!is_array($chRow)) {         return $reArr;     }     else {         if(empty($chRow['maintable'])) $chRow['maintable'] = 'dede_archives';     }       if($chRow['issystem']!=-1)     {         $nquery = " Select arc.*,tp.typedir,tp.topid,tp.namerule,tp.moresite,tp.siteurl,tp.sitepath                     From `{$chRow['maintable']}` arc left join `dede_arctype` tp on tp.id=arc.typeid                     where arc.id='$aid' ";     }     else     {         $nquery = " Select arc.*,1 as ismake,0 as money,'' as filename,tp.typedir,tp.topid,tp.namerule,tp.moresite,tp.siteurl,tp.sitepath                     From `{$chRow['addtable']}` arc left join `dede_arctype` tp on tp.id=arc.typeid                     where arc.aid='$aid' ";     }       $arcRow $dsql->GetOne($nquery);       $Url = GetFileUrl($aid,$arcRow['typeid'],$arcRow['senddate'],$reArr['title'],$arcRow['ismake'],$arcRow['arcrank'],$arcRow['namerule'],$arcRow['typedir'],$arcRow['money'],$arcRow['filename'],$arcRow['moresite'],$arcRow['siteurl'],$arcRow['sitepath']);     return $Url; }  

转载联系作者并注明出处:http://www.lrxy8690.com.cn/zhanchangxueyuan/17-751-1.html

联系我们

在线咨询:点击这里给我发消息

微信号:13798602387

工作日:8:30-23:30,节假日休息