• 全国400电话网上服务平台
    强大号码库资源任选,方便,快捷,快速开通。
    咨询热线:400-1100-266  

    dedecms 调用指定栏目,指定作者,指定自定义字段
    POST TIME:2021-05-24 03:09

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

     

    模板里调用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;
    }
     

    
    关于我们 | 付款方式 | 建站知识 | 增值服务 | 网站模板
    Copyright © 2003-2016
    时间:9:00-21:00 (节假日不休)
    版权所有:巨人网络(扬州)科技有限公司
    总部地址:江苏省信息产业基地11号楼四层
    《增值电信业务经营许可证》 苏B2-20120278
    X

    截屏,微信识别二维码

    微信号:veteran88

    (点击微信号复制,添加好友)

     打开微信

    微信号已复制,请打开微信添加咨询详情!