您当前的位置:首页 > 计算机 > 服务器 > 万维网站 > WordPress

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

时间:02-28来源:作者:点击数:

方法一

找到主题内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++; ?>

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

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门