【发布时间】:2023-03-11 00:50:01
【问题描述】:
我在尝试在帖子之间插入 Google Adsense 代码时遇到了一些问题。首先,看下图:
我的主页上有一个包含 12 个帖子的网格,每行包含 3 个帖子。
我怎么能在第一行的第二个帖子上放一个 Adsense 广告,然后在第二行 os 帖子之后再放一个与容器全长相同大小的广告代码,然后在第 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>
【问题讨论】:
-
为了回答这个问题,我认为你需要提供一些关于你的 CSS 和你正在使用的
grid布局的信息。 -
我正在使用这个主题link,但通过 content.php(显示帖子)和 css(框宽度)修改为每行 3 个帖子。
-
拜托,我只需要一种在特定位置发布广告的方法。我知道有没有办法改变上面的 php 计数器以在特定位置显示广告,但我不知道我是怎么做的。当我输入示例中的代码时,广告显示,但它不是帖子,然后计数器在计数为 3 时换行。但是,在第 1 行中间有一个广告,计数在第三行中断,留给我的布局:第 1 行:发布广告 发布第 2 行:发布(单独)----第三行的计数器中断 --- 第 3 行:发布 POST
标签: wordpress grid row adsense posts