WordPress首页文章定位及广告添加

  • 2,594 views
  • 阅读模式

WordPress首页文章定位及广告添加

方法一

找到主题内index.php文件,寻找<?php the_content(); ?>语句,在其后面加上以下代码:

<?php if ($wp_query->current_post == 1) : ?>  
//广告代码  
<?php endif; ?>  

说明:$wp_query->current_post可以获取当前是第几篇文章,也可以通过$wp_query->current_post % 5 = 1来实现插入多条(第一条位置开始,每五篇文章后插入一条广告)

方法二

通过定义添加index来获取当前文章位置。

while (have_posts()) : the_post();前增加$postIndex = 1;

然后在the_content(); 后加上

<?php if ($postIndex  == 1) : ?>


//广告代码


<?php endif; $postIndex++; ?>

殊途同归,其实两种方法类似,都能实现在首页指定文章位置插入广告的目的。

weinxin
扫码关注微信公众号--IT老五
微信扫一扫关注公众号,获取更多实用app,订阅地址不定时更新
Liu, Thinkin
  • 本文由 发表于 2019-08-29 22:47:11
  • 转载请务必保留本文链接:https://itlao5.com/1070.html
评论  0  访客  0
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定