我在尝试在帖子之间插入 Google Adsense 代码时遇到一些问题。首先,看一下下面的图片:
我的主页上有一个包含 12 个帖子的网格,每行包含 3 个帖子。
我如何才能在第一行的第二个帖子上放置一个 Adsense 广告,然后在第二行操作系统帖子之后放置另一个与容器全长相同大小的广告代码,然后在第 11 个帖子上放置另一个广告。
我知道这是可能的,但我真的很挣扎。
index.php
循环:
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php hct_content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'hct' ); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'hct' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
<?php endif; ?>
</div><!-- #content -->
以及 content.php
代码,由 index.php
调用:
<?php $count = $wp_query->current_post;
$c = fmod($count,3);
if ($c == '2') : ?>
<div style="clear:both;"></div>
最佳答案
这可以通过在 <?php endwhile; ?>
之前添加此内容来完成.
这将在每 6 条帖子后显示一些内容(在本例中是您的广告)
<?php $postnum++; if($postnum%6 == 0) { ?>
...DO SOMETHING..
<?php } ?>
关于wordpress - WordPress 中帖子网格循环之间的 Adsense 广告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27984357/