title
菜鸟吧 首页 站长学堂 dede教程 查看内容

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

2020-02-28 11:54| 发布者: admin| 查看: 1| 评论: 0|原作者: 菜鸟哥

摘要: 百度知道里看到有人提问,帮写了一个。模板里调用SQL:{dede:sql sql="select a.id,a.title,a.writer,a.pubdate,a.typeid,b.aid,b.se……

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


模板里调用SQL:

{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的。

functionGetOneDocUrl($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 asismake,0 asmoney,''asfilename,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;
}

路过

雷人

握手

鲜花

鸡蛋

最新评论

Archiver 手机版 小黑屋 网站地图

Copyright © 2015-2026 菜鸟吧论坛 |找资源研究学习当然上菜鸟吧论坛

警告:本站所有资源收集世界互联网,请下载后24小时之内删除,否則後果自負!
WARNING: ‌All resources from the web. Delete within 24 hours or consequences at your own risk!
郑重声明:站内所有资源均来自互联网或会员投稿发布, 如果侵犯了权益请联系删除,E-mail:cainiaovip8@qq.com 商用请购买正版。

返回顶部