在 WordPress 的类别、存档、标签和搜索页面中插入广告

Insert ads within category, archive, tag & search page for WordPress

我喜欢在 WordPress 网站的类别、存档、标签和搜索页面列表的中间插入 adsense。这是我可以在网上找到的最接近的解决方案:

<?php $postcounter = 1;
if (have_posts()) : ?>
<?php while (have_posts()) : $postcounter = $postcounter + 1;
the_post(); ?>
<?php if(4 == $postcounter)
{ echo ' <div id="adsbetween">
<center> YOUR_ADSENSE_CODE </center>
</div> ' ;
} ?>

我需要帮助来应用我在下面的主题中的内容:

if (($cat_layout == 'masonry-3') || ($cat_layout == 'masonry-2')) {
    echo '<div class="module-masonry-wrapper clear-fix">';
    echo '<div class="masonry-content-container">';

    while (have_posts()): the_post();
        echo kid_masonry_render(get_the_ID());
    endwhile;

    echo '</div></div>';

这是另一个例子:

echo '<div class="classic-blog-content-container">';
while (have_posts()): the_post();
    echo kid_classic_blog_render(get_the_ID(), 35);
endwhile;
echo '</div>';

代码应在第 4 个列表后显示 ADSENSE_CODE。

有什么帮助吗?

这应该注入 adsense 并让循环继续(我想这就是你想要的)。

if($cat_layout=='masonry-3' || $cat_layout=='masonry-2'){
    $postcounter=1;
    echo '<div class="module-masonry-wrapper clear-fix">';
        echo '<div class="masonry-content-container">';
            while(have_posts()){
                if($postcounter==4){
                    echo '<div id="adsbetween"><center>YOUR_ADSENSE_CODE</center></div>';
                }
                the_post();
                echo kid_masonry_render(get_the_ID());
                ++$postcounter;
            }
        echo '</div>';
    echo '</div>';
}

额外的案例:

$postcounter=1;
echo '<div class="classic-blog-content-container">';
    while(have_posts()){
        if($postcounter==4){
            echo '<div id="adsbetween"><center>YOUR_ADSENSE_CODE</center></div>';
        }
        the_post();
        echo kid_classic_blog_render(get_the_ID(),35);
        ++$postcounter;
    }
echo '</div>';'