还有什么不可以 發表於 2024-2-3 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";'>
        本文实例讲述了织梦DeDeCMS动态热点文章排行调用方法。分享给大家供大家参考。具体实现方法如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        在DEDEcms的列表模板和文章模板中,想要显示本类的热点文章排行,是这样调用的:<br>
         </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>
        代码如下:</div>
<div class="msgborder" id="phpcode2" 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";'>
        {dede:arclist row="10" titlelen="38" orderby="click"}<br>
        &lt;li&gt;&lt;a href=""&gt;<br>
        {/dede:arclist}</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>能正常工作,但是有一个问题,如果是用的织梦模板静态页,则要每次生成时才能变化,不能实时更新,除非更新全站.</span>
<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";'>
        后来想到是不是可以用“自定义宏标记”的JS调用实现,问题出现了,这个JS调用不能获取当前环境的typeid,当然你不可能在上面的标签中指定typeid,那样的话就不通用了,只能第个栏目定义一个.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        打开mytab_js.php文件,发现代码是生成一个缓存文件,这个缓存文件是定时才能更新的,不是实时的,把那些代码去掉后,然后另存为“mytag_js_hot.php",如下:"<br>
         </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>
        代码如下:</div>
<div class="msgborder" id="phpcode3" 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";'>
        require_once(dirname(__FILE__).'/../include/common.inc.php'); <br>
        require_once(DEDEINC.'/arc.partview.class.php'); <br>
        if(isset($arcID)) $aid = $arcID; <br>
        $arcID = $aid = (isset($aid) &amp;&amp; is_numeric($aid)) ? $aid : 0; <br>
        if($aid==0) die(" document.write('Request Error!'); "); <br><br>
        //这是新加的代码,表示typeid <br>
        if(isset($typeID)) $tid = $typeID; <br>
        $typeID = $tid = (isset($tid) &amp;&amp; is_numeric($tid)) ? $tid : 0; <br>
        if($tid==0) die(" document.write('Request Error!'); "); <br>
        $pv = new PartView($typeid=$typeID); <br>
        $row = $pv-&gt;dsql-&gt;GetOne(" SELECT * FROM `dede_mytag` WHERE aid='$aid' "); <br>
        if(!is_array($row)) <br>
        { <br>
        $myvalues = " "; <br>
        } <br>
        else <br>
        { <br>
        $tagbody = $row['normbody']; <br>
        $pv-&gt;SetTemplet($tagbody, 'string'); <br>
        $myvalues = $pv-&gt;GetResult(); <br>
        $myvalues = str_replace('"','\"',$myvalues); <br>
        $myvalues = str_replace("\r","\\r",$myvalues); <br>
        $myvalues = str_replace("\n","\\n",$myvalues); <br>
        $myvalues = " \r\n"; <br>
        //file_put_contents($cacheFile, $myvalues); <br>
        echo $myvalues; //不写入缓存文件,直接输出JS代码 <br>
        }</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>调用时用就OK了,注释标注部分是新建的文件和增加的tid指定,其他的动态调用我觉得道理差不多,DeDeCMS全站静态,个别的地方动态,通过JS方式实现.</span>
<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";'>
        希望本文所述对大家的dedecms建站有所帮助。</p>
頁: [1]
查看完整版本: 织梦DeDeCMS动态热点文章排行调用方法