Friday, July 30, 2010 22:33

Wordpress 首页第一篇文章后插入广告

符合标签:
Posted by Boke on 星期三, 十二月 31, 2008, 16:24
这篇文章发表于 WordPress 技巧 目录有 0 条评论 这些 .
转载请给出原文链接:http://www.bokekongjian.com/wordpress/wordpress-jiqiao/first-ads-wordpress-index/

不使用插件的情况下给 Wordpress 的首页插广告,其中广告只在第一篇文章后显示,偶尔也需要第二篇后显示。最简单的方法应该是把显示楼层数的思路拿过来。

首先,编辑 index.php,如果你的archive.php 或者 category.php 与index.php类似,那么你都可以照如下方法编辑:

  1. <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

之前插入

  1. <?php $postcnt = 1; ?>

然后,找到

  1. <?php the_content(); ?>

,在它后面写:

  1. <?php if ($postcnt == 1) : ?>
  2. 广告代码
  3. <?php endif; $postcnt++; ?>

然后目的实现。这个应该不止可以用来插广告。

如果要在第二篇甚至第三篇也显示广告只用写:

  1. <?php if ($postcnt==1 or $postcnt==2) : ?>

广告管理就很方便了,关键是无需插件。

另外一种更为简单的方法:

  1. <?php if ($wp_query->current_post == 0) : ?>
  2. 广告代码位置
  3. <?php endif; ?>

参考:ishawn.netDenis

您可能感兴趣的文章


您可以 回复 , 或者 返回 日志顶部。 .

请留言