织梦DEDEMS调用当前栏目TAG,调用指定栏目下面子集栏目TAG,指定栏目TAG详解

织梦DEDEMS调用当前栏目TAG,调用指定栏目下面子集栏目TAG,指定栏目TAG详解:

列表页可以用下面这个:

 {dede:type}
   [field:id runphp=yes]
    $tsql2 = new DedeSql(false);
    $typelink2 = '';
    $tsql2->SetQuery("SELECT DISTINCT t.tag FROM dede_tagindex t, dede_taglist l WHERE t.id = l.tid AND l.typeid='@me' ORDER BY t.count DESC,t.addtime DESC LIMIT 0,40");
    $tsql2->Execute('t');
    while($row2 = $tsql2->GetArray('t',MYSQL_ASSOC))
    {           
    $typelink2 .= "".$row2['tag']."  ";           
    }
    @me = $typelink2;
   [/field:id]          
{/dede:type}  

频道或封面页必须用下面这种:需要指定当前栏目的ID,在新版里面支持,在老版本dedecms里面不支持。

{dede:type}
   [field:id runphp=yes]     
    $tsql1 = new DedeSql(false);
    $stypeid = '';
    $typelink1 = '';
    $strSql1 = "SELECT id FROM dede_arctype WHERE reid='@me' ";
    $tsql1->SetQuery($strSql1);
    $tsql1->Execute('t1');
    while($row1 = $tsql1->GetArray('t1',MYSQL_ASSOC))
    {
     $stypeid .= 'l.typeid='.$row1['id'].'||'; 
     $stypeid .= typeall($row1['id']);
    }  
    if ($stypeid != ""){   
     @me = cn_substr($stypeid,strrpos($stypeid,'||'),0); 
    }else{
     @me = 'l.typeid='.@me;
    }  
    $numi = 0;         
    $strSql = "SELECT DISTINCT t.tag FROM dede_tagindex t,dede_taglist l WHERE t.id = l.tid AND ('@me') ORDER BY t.count DESC,t.addtime DESC LIMIT 0,40";
    $tsql1->SetQuery($strSql);
    $tsql1->Execute('t');
    while($row2 = $tsql1->GetArray('t',MYSQL_ASSOC))
    {     
     if ($numi == 0){
      $typelink1 .= "
  • "; $typelink1 .= "".cn_substr($row2['tag'],6,0).""; }else if($numi%5 == 0){ $typelink1 .= "
  • "; $typelink1 .= "
  • "; $typelink1 .= "".cn_substr($row2['tag'],6,0).""; }else{ $typelink1 .= "".cn_substr($row2['tag'],5,0).""; } $numi = $numi + 1; } function typeall($reid=0){ $dbobj2 = new DedeSql(false); $strSql1 = "SELECT id FROM xingfu.yuer_arctype WHERE reid = $reid || topid=$reid"; $dbobj2->SetQuery($strSql1); $dbobj2->Execute('f'); while($row = $dbobj2->GetArray('f',MYSQL_ASSOC)) { $stypeid .= 'l.typeid='.$row['id'].'||'; //结果赋值 typeall($row['id']); } return $stypeid; } @me = $typelink1; [/field:id] {/dede:type}
  • 随机读取当前栏目的tag标签:

    {dede:type}
       [field:id runphp=yes]
        $tsql2 = new DedeSql(false);
        $typelink2 = '';
        $tsql2->SetQuery("SELECT * FROM dede_archives a LEFT JOIN dede_taglist t ON a.id=t.aid WHERE a.typeid=@me ORDER BY rand() LIMIT 0,14");
        $tsql2->Execute('t');
        while($row2 = $tsql2->GetArray('t',MYSQL_ASSOC))
        {           
        $typelink2 .= "
  • ".$row2['tag']."
  • "; } @me = $typelink2; [/field:id] {/dede:type}

    指定栏目读取

    {dede:sql sql="select * from dede_archives a left join dede_taglist t on a.id=t.aid where a.typeid=2 limit 0,10 "}
    [field:tag /]
    
    {/dede:sql}

    备注:‍typeid=2 是你的栏目ID,根据自己需要写

              limit 0,10 是tag的条数。

    补充:这个标签是通用的: {dede:tag type='current'/}

    转载自:http://wangzhan.jiaxiangz.com

    你可能感兴趣的:(DEDEcms教程)