dedecms通过标签调用相关文章

2012-01-11 09:48 来源:www.chinab4c.com 作者:dedecms专家

    dedecms通过标签调用相关文章,主要是通过标签tag以及 标签对应的文章,这样就可以最大限度的通过dedecms文章内容中的数据,调用相关文章。达到提高网站内容质量的效果。具体的代码如下.

    1:以下是标签arctag

     <?php   if(!defined('DEDEINC')) exit('Request Error!');

 
function lib_arctag(&$ctag,&$refObj)
{
 
    global $dsql;
 $ar = "row|10";
 FillAttsDefault($ctag->CAttribute->Items);
 extract($ctag->CAttribute->Items);
 $innertext = $ctag->GetInnerText();
 $tcp = new DedeTagParse();
 $tcp->SetNameSpace("field","[","]");
 $tcp->LoadSource($innertext);
 $aid = $refObj->Fields['id'];
 $revalue = '';
 if($aid){
  $ids = array();
  $tag = array();
  $dsql->Execute("f","select tag from dede_taglist where aid = '$aid'");
  while($re=$dsql->GetArray("f")){
   
   $tag[] = $re['tag'];

  }

  if($tag){
   
   foreach($tag as $tk){
    
    $dsql->Execute("f1","select aid from dede_taglist where tag = '$tk'");
    while($re1=$dsql->GetArray("f1")){
     
     $ids[] = $re1['aid'];

    }

   }

  }
  
  

  if($ids){
   
   $ids  =array_unique($ids);
   $sqa = "(".join(",",$ids).")";
   
   $query = "SELECT se.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
            FROM `dede_archives` se LEFT JOIN `dede_arctype` tp ON se.typeid=tp.id WHERE  se.id in $sqa limit $row";
   
   $dsql->Execute("f2",$query);
   
   while($row1 = $dsql->GetArray("f2")){
    
    $row1['arcurl'] = GetFileUrl($row1['id'],$row1['typeid'],$row1['senddate'],$row1['title'],
                    $row1['ismake'],
                    $row1['arcrank'],$row1['namerule'],$row1['typedir'],$row1['money'],
                    $row1['filename'],$row1['moresite'],$row1['siteurl'],$row1['sitepath']);
    $row1['title'] = cn_substr($row1['title'],10);
    
    foreach($tcp->CTags as $tid=>$tt){
     
     $tcp->Assign($tid,$row1[$tt->GetName()]);


    }
    $revalue.=$tcp->GetResult();
   }
  }

 }

 
  
   return $revalue;
}

     2:模板中调用方式.

      {dede:arctag id=10}
 <a href="[field:arcurl/]">[field:title/]</a>
{/dede:arctag}

    以上就达到了在dedecms文章页面调用相关标签下的文章了。

    来源:http://www.chinab4c.com