首頁 > CMS教程 > DEDECMS > dedecms織夢tag keyword怎麼呼叫相關文章

dedecms織夢tag keyword怎麼呼叫相關文章

藏色散人
發布: 2019-12-16 09:50:02
原創
1952 人瀏覽過

dedecms織夢tag keyword怎麼呼叫相關文章

dedecms織夢tag keyword怎麼呼叫相關文章?

DEDE官方的dede:likearticle是利用文章中輸入的關鍵字或自動分詞形成的關鍵字來關聯文章,但有時候自動產生的關鍵字並不精確,造成關聯不準,這裡我們透過自訂一個類別庫檔案來實作精準取得相關文章

推薦學習:織夢cms

可以單用tag來呼叫相關文章,也可用tag keyword來呼叫相關文章(預設tag優先於keyword,可以自己排序)

在\include\taglib\ 下新增一個liketags.lib.php 程式碼如下

<?php
if(!defined(&#39;DEDEINC&#39;)) exit(&#39;Request Error!&#39;);
function lib_liketags(&$ctag,&$refObj)
{
    global $dsql;
      
    //属性处理
    $attlist="row|12,titlelen|30,infolen|250,col|1,tablewidth|100,mytypeid|0,byabs|0,imgwidth|1,imgheight|90,flag|";
    FillAttsDefault($ctag->CAttribute->Items,$attlist);
    extract($ctag->CAttribute->Items, EXTR_SKIP);
    $revalue = &#39;&#39;;
      
    if(empty($tablewidth)) $tablewidth = 100;
    if(empty($col)) $col = 1;
    $colWidth = ceil(100/$col);
    $tablewidth = $tablewidth."%";
    $colWidth = $colWidth."%";
$orwheres = &#39;&#39;;
if($flag != &#39;&#39;) {
$flags = explode(&#39;,&#39;, $flag);
for($i=0; isset($flags[$i]); $i++) $orwheres .= " AND FIND_IN_SET(&#39;{$flags[$i]}&#39;, arc.flag)>0 ";
}
  
    $ids = array();
    $tids = array();
      
    if(!empty($refObj->Fields[&#39;tags&#39;])) {
        $keyword = $refObj->Fields[&#39;tags&#39;];
    }
    else {
        $keyword = ( !empty($refObj->Fields[&#39;keywords&#39;]) ? $refObj->Fields[&#39;keywords&#39;] : &#39;&#39; );
    }
      
    $typeid = ( !empty($mytypeid) ? $mytypeid : 0 );
    if(empty($typeid))
    {
        if(!empty($refObj->Typelink->TypeInfos[&#39;reid&#39;])) {
             $typeid = $refObj->Typelink->TypeInfos[&#39;reid&#39;];
        }
        else {
             if(!empty($refObj->Fields[&#39;typeid&#39;])) $typeid = $refObj->Fields[&#39;typeid&#39;];
        }
    }
      
    if( !empty($typeid) && !preg_match(&#39;#,#&#39;, $typeid) ) {
        $typeid = GetSonIds($typeid);
    }
      
if(!empty($refObj->Fields[&#39;tags&#39;]) && $eregtype != &#39;keyword&#39; )
{
$tags = explode(&#39;,&#39;, addslashes($refObj->Fields[&#39;tags&#39;]));
$getsql = " tag like &#39;".join("&#39; OR tag like &#39;", $tags)."&#39; ";
$dsql->Execute(&#39;me&#39;, "Select * From `dede_tagindex` where $getsql ");
while($arow = $dsql->GetArray(&#39;me&#39;))
{
$tids[] = $arow[&#39;id&#39;];
}
$tid = join(&#39;,&#39;, $tids);
if($tid!=&#39;&#39;)
{
061
$dsql->Execute("me", "Select aid From `dede_taglist` where tid in($tid) And arcrank > -1 group by aid order by aid desc");
while($arow = $dsql->GetArray("me"))
{
$ids[] = $arow[&#39;aid&#39;];
$arcid =  $refObj->Fields[&#39;aid&#39;];
}
}
}
if($eregtype == &#39;tag&#39; && count($ids) == 0 )
{
return;
}
else
{
if(count($ids) > 0)
{
if(!empty($typeid))
{
$typeid = " And arc.typeid in($typeid) And arc.id<>$arcid ";
}
$idsStr = join(&#39;,&#39;, $ids);
$query = "Select arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,
tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
from `dede_archives` arc left join `dede_arctype` tp on arc.typeid=tp.id
where arc.arcrank>-1 and arc.id in($idsStr) $typeid order by arc.id desc limit 0, $row";
}
else
{
$limitRow = $row - count($ids);
$keyword = &#39;&#39;;
if(!empty($refObj->Fields[&#39;keywords&#39;]))
{
$keywords = explode(&#39;,&#39; , trim($refObj->Fields[&#39;keywords&#39;]));
$keyword = &#39;&#39;;
$n = 1;
foreach($keywords as $k)
{
if($n > 3)  break;
  
if(trim($k)==&#39;&#39;) continue;
else $k = addslashes($k);
  
$keyword .= ($keyword==&#39;&#39; ? " CONCAT(arc.keywords,&#39; &#39;,arc.title) like &#39;%$k%&#39; " : " OR CONCAT(arc.keywords,&#39; &#39;,arc.title) like &#39;%$k%&#39; ");
$n++;
}
}
$arcid = (!empty($refObj->Fields[&#39;id&#39;]) ? $refObj->Fields[&#39;aid&#39;] : 0);
if( empty($arcid) || $byabs==0 )
{
$orderquery = " order by arc.id desc ";
}
else
{
$orderquery = " order by ABS(arc.id - ".$arcid.") ";
}
if($keyword != &#39;&#39;)
{
if(!empty($typeid))
{
$typeid = " And arc.typeid in($typeid) And arc.id<>$arcid ";
}
$query = "Select arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,
tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
from `dede_archives` arc left join `dede_arctype` tp on arc.typeid=tp.id
where arc.arcrank>-1 and ($keyword)  $typeid $orderquery limit 0, $row";
}
else
{
if(!empty($typeid))
{
$typeid = " arc.typeid in($typeid) And arc.id<>$arcid ";
}
$query = "Select arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,
tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
from `dede_archives` arc left join `dede_arctype` tp on arc.typeid=tp.id
where arc.arcrank>-1 and  $typeid $orderquery limit 0, $row";
}
}
}
  
    $innertext = trim( $ctag->GetInnerText() );
    if($innertext==&#39;&#39;) $innertext = GetSysTemplets(&#39;part_arclist.htm&#39;);
    $dsql->SetQuery($query);
    $dsql->Execute(&#39;al&#39;);
    $artlist = &#39;&#39;;
    if($col > 1){
        $artlist = "<table width=&#39;$tablewidth&#39; border=&#39;0&#39; cellspacing=&#39;0&#39; cellpadding=&#39;0&#39;>\r\n";
    }
    $dtp2 = new DedeTagParse();
    $dtp2->SetNameSpace(&#39;field&#39;, &#39;[&#39;, &#39;]&#39;);
    $dtp2->LoadString($innertext);
    $GLOBALS[&#39;autoindex&#39;] = 0;
    $line = $row;
    for($i=0; $i < $line; $i++)
    {
        if($col>1) $artlist .= "<tr>\r\n";
        for($j=0; $j < $col; $j++)
        {
            if($col>1) $artlist .= "    <td width=&#39;$colWidth&#39;>\r\n";
            if($row = $dsql->GetArray("al"))
            {
                $ids[] = $row[&#39;id&#39;];
                //处理一些特殊字段
                $row[&#39;info&#39;] = $row[&#39;infos&#39;] = cn_substr($row[&#39;description&#39;],$infolen);
                $row[&#39;id&#39;] =  $row[&#39;id&#39;];
  
                if($row[&#39;corank&#39;] > 0 && $row[&#39;arcrank&#39;]==0)
                {
                    $row[&#39;arcrank&#39;] = $row[&#39;corank&#39;];
                }
  
                $row[&#39;filename&#39;] = $row[&#39;arcurl&#39;] = GetFileUrl($row[&#39;id&#39;],$row[&#39;typeid&#39;],$row[&#39;senddate&#39;],$row[&#39;title&#39;],$row[&#39;ismake&#39;],
                $row[&#39;arcrank&#39;],$row[&#39;namerule&#39;],$row[&#39;typedir&#39;],$row[&#39;money&#39;],$row[&#39;filename&#39;],$row[&#39;moresite&#39;],$row[&#39;siteurl&#39;],$row[&#39;sitepath&#39;]);
  
                $row[&#39;typeurl&#39;] = GetTypeUrl($row[&#39;typeid&#39;],$row[&#39;typedir&#39;],$row[&#39;isdefault&#39;],$row[&#39;defaultname&#39;],$row[&#39;ispart&#39;],
                $row[&#39;namerule&#39;],$row[&#39;moresite&#39;],$row[&#39;siteurl&#39;],$row[&#39;sitepath&#39;]);
  
                if($row[&#39;litpic&#39;] == &#39;-&#39; || $row[&#39;litpic&#39;] == &#39;&#39;)
                {
                    $row[&#39;litpic&#39;] = $GLOBALS[&#39;cfg_cmspath&#39;].&#39;/images/defaultpic.gif&#39;;
                }
                if(!preg_match("#^http:\/\/#i", $row[&#39;litpic&#39;]) && $GLOBALS[&#39;cfg_multi_site&#39;] == &#39;Y&#39;)
                {
                    $row[&#39;litpic&#39;] = $GLOBALS[&#39;cfg_mainsite&#39;].$row[&#39;litpic&#39;];
                }
                $row[&#39;picname&#39;] = $row[&#39;litpic&#39;];
                $row[&#39;stime&#39;] = GetDateMK($row[&#39;pubdate&#39;]);
                $row[&#39;typelink&#39;] = "<a href=&#39;".$row[&#39;typeurl&#39;]."&#39;>".$row[&#39;typename&#39;]."</a>";
                $row[&#39;image&#39;] = "<img src=&#39;".$row[&#39;picname&#39;]."&#39; border=&#39;&#39; width=&#39;$imgwidth&#39; height=&#39;$imgheight&#39; alt=&#39;".preg_replace("#[&#39;><]#","",$row[&#39;title&#39;])."&#39;>";
                $row[&#39;imglink&#39;] = "<a href=&#39;".$row[&#39;filename&#39;]."&#39;>".$row[&#39;image&#39;]."</a>";
                $row[&#39;fulltitle&#39;] = $row[&#39;title&#39;];
                $row[&#39;title&#39;] = cn_substr($row[&#39;title&#39;], $titlelen);
                if($row[&#39;color&#39;]!=&#39;&#39;) $row[&#39;title&#39;] = "<font color=&#39;".$row[&#39;color&#39;]."&#39;>".$row[&#39;title&#39;]."</font>";
                if(preg_match(&#39;#b#&#39;, $row[&#39;flag&#39;])) $row[&#39;title&#39;] = "<strong>".$row[&#39;title&#39;]."</strong>";
                $row[&#39;textlink&#39;] = "<a href=&#39;".$row[&#39;filename&#39;]."&#39;>".$row[&#39;title&#39;]."</a>";
                $row[&#39;plusurl&#39;] = $row[&#39;phpurl&#39;] = $GLOBALS[&#39;cfg_phpurl&#39;];
                $row[&#39;memberurl&#39;] = $GLOBALS[&#39;cfg_memberurl&#39;];
                $row[&#39;templeturl&#39;] = $GLOBALS[&#39;cfg_templeturl&#39;];
                  
                if(is_array($dtp2->CTags))
                {
                    foreach($dtp2->CTags as $k=>$ctag)
                    {
                        if($ctag->GetName()==&#39;array&#39;) {
                            $dtp2->Assign($k,$row);
                        }
                        else {
                            if(isset($row[$ctag->GetName()])) $dtp2->Assign($k,$row[$ctag->GetName()]);
                            else $dtp2->Assign($k,&#39;&#39;);
                        }
                    }
                    $GLOBALS[&#39;autoindex&#39;]++;
                }
  
                $artlist .= $dtp2->GetResult()."\r\n";
            }
            //if hasRow
            else
            {
                $artlist .= &#39;&#39;;
            }
            if($col>1) $artlist .= "    </td>\r\n";
        }
        //Loop Col
        if($col>1) $i += $col - 1;
        if($col>1) $artlist .= "    </tr>\r\n";
    }
    //loop line
    if($col>1) $artlist .= "    </table>\r\n";
    $dsql->FreeResult("al");
    return $artlist;
}
登入後複製

前台模板調用

{dede:liketags row=&#39;3&#39; mytypeid=&#39;6&#39; eregtype=&#39;all|tag|keyword&#39; titlelen=&#39;250&#39; infolen=&#39;250&#39;}
<li>
<a href="[field:arcurl/]" title="[field:title/]" target="_blank">
<div class="list-img">
<img src="[field:litpic/]" alt="[field:title/]"/>
</div>
<div class="list-info">
<p class="title">[field:title/]</p>
<p class="meta">[field:description /]</p>
</div>
</a>
</li>
{/dede:liketags}
登入後複製

以上是dedecms織夢tag keyword怎麼呼叫相關文章的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板