免费发布信息
微信公众号

dedecms织梦tag keyword怎么调用相关文章

   来源:黔优网责任编辑:优优  时间:2024-09-23 11:16:56 浏览量:1

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;] = "@@##@@<]#","",$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">
@@##@@
</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怎么调用相关文章的详细内容,更多请关注本网内其它相关文章!

 
 
 
没用 0举报 收藏 0
免责声明:
黔优网以上展示内容来源于用户自主上传、合作媒体、企业机构或网络收集整理,版权争议与本站无关,文章涉及见解与观点不代表黔优网官方立场,请读者仅做参考。本文标题:dedecms织梦tag keyword怎么调用相关文章,本文链接:https://www.qianu.com/help/49824.html,欢迎转载,转载时请说明出处。若您认为本文侵犯了您的版权信息,或您发现该内容有任何违法信息,请您立即点此【投诉举报】并提供有效线索,也可以通过邮件(邮箱号:kefu@qianu.com)联系我们及时修正或删除。
 
 

 

 
推荐图文
推荐帮助中心
最新帮助中心