你好,我有一个小问题。我们新网站的首页有一系列带有翻转的缩略图框,可以打开某些展示的产品。我写的循环显示了当前的所有帖子,但最终将只绑定到投资组合类别。
然而,我的经理希望在第三篇文章之后有一个带有最近博客文章的滑块,以及在第 5 篇和第 7 篇文章之后再添加几个带有引用等的滑块。我发现了一些代码,每 n 个帖子都注入相同的代码段,但这对我没有好处,因为我只希望它发生 3 次并且所有内容都不同,包括一个在循环内有一个循环(大概时间会慢慢移动超级哈哈)。这可能吗?如果是这样,有人可以指出我的代码片段吗?
电流回路
<!-- Start of loop -->
<?php if (have_posts()) : ?>
<!-- Start of Post -->
<?php while (have_posts()) : the_post(); ?>
<!-- Check to see if there is featured image -->
<?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) { ?>
<?php $img_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array( 960,960 )); ?>
<!-- End Checking -->
<div class="portfolioblock" style="background-image: url('<?php echo $img_src[0]; ?>');">
<a href="<?php the_permalink(); ?>">
<div class="rollover">
<div class="center">
<img src="<?php bloginfo('template_url'); ?>/img/zoom.png" alt="More" />
</div>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
</div>
</a>
</div>
<!-- Start Content Block -->
<?php } else { ?>
<div class="block">
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
</div>
<?php } ?>
<!-- End Content Block -->
<?php endwhile; ?>
<!-- End of Post -->
<?php else : ?>
//Something that happens when a post isn’t found.
<?php endif; ?>
<!-- End of Loop -->
我发现这段代码用于每 n 个帖子注入一个代码片段。
<?php $postnum++; if($postnum%5 == 0) { ?>
YOUR AD CODE HERE
<?php } ?>