尘芥 發表於 2023-10-4 00:00:00

DEDECMS相关文章以关键字相关的修改方法(自定义函数)

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        现在终于出了解决办法:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        1 在 inc_functions.php 最后?&gt;前 加上</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        <p>
                代码如下:</p>
</div>
<div class="msgborder" id="phpcode15" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        //查询指定栏目里包含相应关键字的文章,并列出 <br>
        //参数说明:$showImg 是否显示缩略图,0表示不显示,1表示显示 <br>
        // $titleLen 标题长度,0表示无限 <br>
        // $rowCount 输出行数,0表示无限 <br>
        // $typeid 栏目ID,0表示所有栏目 <br>
        // $keyWord 关键字,字符串 <br>
        function ShowKeyWordArc($showImg,$titleLen,$rowCount,$typeid,$keyWord){ <br>
        $dsql = new DedeSql(false); <br>
        $sql = TypeGetSunID($typeid,$dsql); &lt;/p&gt; &lt;p&gt;//关键字分词技术 <br>
        $ks = explode(" ",$keyWord); <br>
        foreach($ks as $k){ <br>
        $k = trim($k); <br>
        if ($k!="") { <br>
        $kwsqlarr[] = " (xkzzz_archives.title like '%$k%')"; <br>
        //$kwsqlarr[] = " (xkzzz_archives.keywords like '%$k%') "; //如果需要相关到其它文章的关键字,解除此行注释 <br>
        } <br>
        } <br>
        $where = implode(' OR ',$kwsqlarr); &lt;/p&gt; &lt;p&gt;$sql="Select tp.namerule,tp.typedir,xkzzz_full_search.aid,xkzzz_full_search.url,xkzzz_archives.* From xkzzz_full_search left join xkzzz_archives on xkzzz_full_search.aid=xkzzz_archives.ID left join xkzzz_arctype tp on xkzzz_archives.typeid=tp.ID where {$sql} and ((xkzzz_archives.title like '%".$keyWord."%') or $where) order by xkzzz_full_search.aid desc"; <br>
        $dsql-&gt;SetQuery($sql); <br>
        $dsql-&gt;Execute(); <br>
        $ss=""; <br>
        $i=0; <br>
        while($row=$dsql-&gt;GetObject()){ <br>
        $url=GetFileUrl($row-&gt;ID,$row-&gt;typeid,$row-&gt;senddate,$row-&gt;title,$row-&gt;ismake,$row-&gt;arcrank,$row-&gt;namerule,$row-&gt;typedir,$row-&gt;money); <br>
        if ($showImg==0){ <br>
        $ss=$ss."&lt;LI&gt;&lt;a href='".$url."' target=_blank&gt;"; <br>
        if ($titleLen!=0) $ss=$ss.cn_substr($row-&gt;title,$titleLen); <br>
        else $ss=$ss.$row-&gt;title; <br>
        $ss=$ss."&lt;/A&gt;&lt;/LI&gt;"; <br>
        }else{ <br>
        $ss=$ss."&lt;LI&gt;&lt;span class='sjdqimggl'&gt;&lt;a href='".$url."' target=_blank&gt;"; &lt;/p&gt; &lt;p&gt;if ($row-&gt;litpic!="") $ss=$ss."&lt;img src='".$row-&gt;litpic."' alt='".$row-&gt;title."' /&gt;"; <br>
        else $ss=$ss."&lt;img src='/images/titl.gif'/&gt;"; <br>
        $ss=$ss."&lt;/a&gt;&lt;/span&gt;&lt;span class='sjdqtxttl'&gt;&lt;a href='".$url."' target=_blank&gt;"; <br>
        if ($titleLen!=0) $ss=$ss.cn_substr($row-&gt;title,$titleLen); <br>
        else $ss=$ss.$row-&gt;title; <br>
        $ss=$ss."&lt;/A&gt;&lt;/span&gt;&lt;/LI&gt;"; <br>
        } <br>
        $i++; <br>
        if (($rowCount!=0)&amp;&amp;($i&gt;=$rowCount)) return $ss; <br>
        } <br>
        return $ss; <br>
        } </div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        2 放在文章模板页内</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        {dede:field name=’keywords’ function=’ShowKeyWordArc(0,32,10,0,”@me”)’/} <br>
        就表示是取所有栏目内的相关文章(与当前文章的关键字相关),标题长度最大32,最多显示10条,不显示缩略图</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        或 <br>
        {dede:field name=’keywords’ function=’ShowKeyWordArc(0,32,10,0,”高三 语文”)’/} <br>
        可以找到标题里,含有“高三 语文”,或者含有“高三”或“语文”的文章</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        例如,这一段:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        相关文章 <br>
        {dede:likeart titlelen=’24′ row=’10′}</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        &lt; &gt; <br>
        {/dede:likeart}</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        就改成:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        相关文章 <br>
        {dede:field name=’keywords’ function=’ShowKeyWordArc(0,32,10,0,”@me”)’/}</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        申明:这个函数不是我写的根据关键字来相关文章,就用户体验以及SEO来说都是非常好的 <br>
        但是唯一不好的地方就是生成静态的时候会慢很多,哈哈,服务器又要辛苦了</p>
頁: [1]
查看完整版本: DEDECMS相关文章以关键字相关的修改方法(自定义函数)