鲁泉 發表於 2023-5-30 00:00:00

织梦dedecms文章列表页随机放入广告的方法

<p>
        有的时候想要再织梦DEDECMS列表页中间,隔一定数量的文章,就想要放一个广告位。如下图所示:</p><p style="text-align:center;"><img style="max-width:100%!important;height:auto!important;" title="织梦dedecms文章列表页随机放入广告的方法" alt="织梦dedecms文章列表页随机放入广告的方法" src="https://zhuji.jb51.net/uploads/img/202305/2e9fdf209e839467c422c9ded2403923.jpg"/></p><p>
        开发教程</p><p>
        1、在后台新建一个广告,模块--&gt;广告管理--&gt;增加一个广告位(增加加广告位就不赘述了,实在不会的,找一下度娘帮忙),我加好了一个如下图所示有两个调用标签,用JS调用代码</p><p style="text-align:center;"><img style="max-width:100%!important;height:auto!important;" title="织梦dedecms文章列表页随机放入广告的方法" alt="织梦dedecms文章列表页随机放入广告的方法" src="https://zhuji.jb51.net/uploads/img/202305/23040e9270047471dd2e80ddbcdb104e.jpg"/></p><blockquote><div>
                &nbsp; <!--预留备用--></div><div>
                &nbsp;</div></blockquote><p>
        2、打开列表页模板,默认的为/templets/default/list_article.htm</p><p>
        找到:{/dede:list}</p><p>
        在它的上面增加以下代码:</p><blockquote><p>
                if(@me%5==&#39;0&#39;) @me=&#39;&#39;; else @me=&#39;&#39;;</p></blockquote><p>
        注释:以上代码中,数字5,表示每隔5篇文章,后面就穿插一个广告。aid=1中的1,代表的是你在后台添加广告位的id。当然这里也可以加各种的样式。如下代码所示:</p><blockquote><p>
                &nbsp; if(@me%5==&#39;0&#39;) @me=&#39;</p><div></div>&#39;; else @me=&#39;&#39;;<p><br/></p><p>
                &nbsp; <!--通过对classname 来对样式进行css的各种控制即可。--></p></blockquote><p>
        保存,重新生成列表页,完成。</p><p>
        升级</p><p>
        当然,还可以更复杂一点。有的时候,穿插一个相同的广告,显得太重复,那就可以多建几个不同的广告位,然后随机调用id就可以了。具体代码如下:</p><blockquote><p>
                &nbsp;<br/>
                &nbsp;&nbsp;&nbsp; if(@me%5==&#39;0&#39;) {<br/>
                &nbsp;&nbsp;&nbsp; $a=array(&quot;1&quot;,&quot;5&quot;,&quot;8&quot;,&quot;9&quot;,&quot;12&quot;);<br/>
                &nbsp;&nbsp;&nbsp; $random_keys=array_rand($a,2);<br/>
                &nbsp;&nbsp;&nbsp; @me=&#39;</p><div></div>&#39;;<br/>
                &nbsp;&nbsp;&nbsp; }<br/>
                &nbsp;&nbsp;&nbsp; else @me=&#39;&#39;;<br/>
                &nbsp;&nbsp;&nbsp; else @me=&#39;&#39;;<p><br/></p></blockquote><p>
        注释:其中&quot;1&quot;,&quot;5&quot;,&quot;8&quot;,&quot;9&quot;,&quot;12&quot;为你想要调用的广告id号</p><p>
        效果如下,为了好截图,我做成每隔两篇文章,就插入一篇广告:</p><p style="text-align:center;"><img style="max-width:100%!important;height:auto!important;" title="织梦dedecms文章列表页随机放入广告的方法" alt="织梦dedecms文章列表页随机放入广告的方法" src="https://zhuji.jb51.net/uploads/img/202305/5b77558a21be707e17155ef3e1ddadf9.jpg"/></p>
頁: [1]
查看完整版本: 织梦dedecms文章列表页随机放入广告的方法