使用过WordPress的朋友应该知道WordPress能够实现在首页文章列表中插入广告,那么Z-Blog PHP能不能实现呢?那是必须能的,方法也不止一种,下面就给大家说下Z-Blog PHP在首页文章列表中任意位置插入广告的方法:(以默认模板为例,其它模板雷同)
1、新建广告文件
在模板文件夹内建一个文件作为放广告代码的文件(这里暂且命名为:post-ad.php)
2、修改模板文件
找到 \zb_users\theme\default\template\index.php (default根据你自己的模板为准)这个文件找到下面这段代码:
Java
{foreach $articles as $article}{if $article.IsTop}{template:post-istop}{else}{template:post-multi}{/if}{/foreach}
如果你只想在置顶列表里加入广告那么将上面的代码替换为:
Java
{php}$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}{/foreach}
备注:数字3为广告出现的位置,post-ad 为第一步建的文件名,下同。
如果你想在除置顶列表外加入广告那么将上面的代码替换为:
Java
{php}$i=1;{/php}{foreach $articles as $article} {if $article.IsTop} {template:post-istop} {else} {template:post-multi} {if $i==3} {template:post-ad} {/if} {php}$i++;{/php} {/if}{/foreach}
上面两个位置同时出现的代码为:
Java
{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}
未经允许不得转载:搬瓦工VPS_美国VPS » ZBlog如何在首页文章列表任意位置插入广告