首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wordpress中每6个帖子的替代标记

wordpress中每6个帖子的替代标记
EN

Stack Overflow用户
提问于 2010-06-12 02:47:27
回答 2查看 474关注 0票数 1

我想把在和广告代码后,每6个帖子在我的博客。我真的想不出如何突破森林,插入广告代码。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-06-12 02:53:43

This link会帮你的。第三个标题是:在第一个帖子后插入广告

更改6的代码,其中代码为2:

代码语言:javascript
复制
<?php if (have_posts()) : ?> // Here we check if there are posts
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?> // While we have posts, add 1 to count
  <?php if ($count == 6) : ?> // If this is post 6
          //Paste your ad code here
          <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> // post title
          <?php the_excerpt(); ?> // You may use the_content too
   <?php else : ?> // If this is not post 6
          <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
          <?php the_excerpt(); ?>
  <?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>

更新:正如戈登注意到的那样,你每6篇帖子就会要求提供代码(很抱歉,我在第一次阅读时就错过了)。所以代码应该是:

代码语言:javascript
复制
<?php if ($count % 6 == 0) : ?>
票数 2
EN

Stack Overflow用户

发布于 2010-06-12 09:28:24

正如@Gordon评论的那样,以下是我如何重构该代码;

代码语言:javascript
复制
<?php if (have_posts()) : $count = 1; while (have_posts()): ?>

    <?php if ($count == 6) : ?>

          // Paste your ad code here

    <?php $count = 0; endif; ?>    

    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_excerpt(); ?>

<?php $count++; endwhile; endif; ?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3025383

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档