以下内容转自恒辉工作室
今天有人在群里问:WordPress在首页文章列表中插入广告都能实现,zblog-php能不能实现呢?那是必须能的,方法也不止一种,下面就给大家说下zblog-php在首页文章列表中任意位置插入广告的方法:(以默认模板为例,其它模板雷同)
1、新建广告文件
在模板文件夹内建一个文件作为放广告代码的文件(这里暂且命名为:post-ad.php)
2、修改模板文件
找到\zb_users\theme\default\template\index.php(default根据你自己的模板为准)这个文件找到下面这段代码:
{foreach $articles as $article} {if $article.IsTop} {template:post-istop} {else} {template:post-multi} {/if} {/foreach}
将上面的代码替换为:
{php}$i=1;$j=1;{/php} {foreach $articles as $article} {if $article.IsTop} {template:post-istop} {if $j==3} {template:post-ad} {/if} {php}$j++;{/php} {else} {template:post-multi} {if $i==3} {template:post-ad} {/if} {php}$i++;{/php} {/if} {/foreach}
其中
{if$j==3}
代表前面有3篇文章
发布于 2017-08-3111:28:54 回复
发布于 2015-04-2310:36:17 回复