我想把在和广告代码后,每6个帖子在我的博客。我真的想不出如何突破森林,插入广告代码。
发布于 2010-06-12 02:53:43
This link会帮你的。第三个标题是:在第一个帖子后插入广告
更改6的代码,其中代码为2:
<?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篇帖子就会要求提供代码(很抱歉,我在第一次阅读时就错过了)。所以代码应该是:
<?php if ($count % 6 == 0) : ?>发布于 2010-06-12 09:28:24
正如@Gordon评论的那样,以下是我如何重构该代码;
<?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; ?>https://stackoverflow.com/questions/3025383
复制相似问题