Home > CMS Tutorial > DEDECMS > Related articles on how to call dedecms dreamweaver tag keyword

Related articles on how to call dedecms dreamweaver tag keyword

藏色散人
Release: 2019-12-16 09:50:02
Original
1991 people have browsed it

Related articles on how to call dedecms dreamweaver tag keyword

dedecmsHow to call related articles with the dreamweaver tag keyword?

DEDE's official dede:likearticle uses keywords entered in the article or keywords formed by automatic word segmentation to associate articles. However, sometimes the automatically generated keywords are not accurate, resulting in inaccurate association. , here we customize a class library file to accurately obtain related articles

Recommended learning: 梦Weavercms

You can use tags alone to call related articles, or Tag keyword can be used to call related articles (default tag takes precedence over keyword, you can sort by yourself)

Add a liketags.lib.php under \include\taglib\ and the code is as follows

<?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;
}
Copy after login

Front-end template call

{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}
Copy after login

The above is the detailed content of Related articles on how to call dedecms dreamweaver tag keyword. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template