wordpress - WordPress 中帖子网格循环之间的 Adsense 广告?

标签 wordpress grid row adsense posts

我在尝试在帖子之间插入 Google Adsense 代码时遇到一些问题。首先,看一下下面的图片:

enter image description here

我的主页上有一个包含 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/

相关文章:

java - 在java中根据另一个列表的值对多个列表进行排序

html - 将 Aria-hidden 更改为 "false"

wordpress - 分析 VPS 性能(运行 WordPress 博客的 VPS)的好工具吗?

php - 防止类为 'sub-menu' 的 ul 元素成为 Wordpress 菜单中列表项的子元素

javascript - 使用 javascript 将值设置为网格中的文本框

haskell - 如何纯粹从功能上快速浏览二维网格?

c# - 如何在 c# 中删除没有 SqlDataSource 的 gridview 中的行?

html - 列不会水平堆叠在一行中

javascript - 滚动 block 的 100% 高度

javascript - 在 Canvas HTML5 中循环网格并在方 block 之间使用 "gaps"?