【问题标题】:Insert ads within category, archive, tag & search page for WordPress在 WordPress 的类别、存档、标签和搜索页面中插入广告
【发布时间】:2017-04-11 09:10:11
【问题描述】:

我喜欢在 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。

有什么帮助吗?

【问题讨论】:

  • 尝试删除$postcounter = $postcounter + 1;并将$postcounter++;放在endwhile;之前

标签: php wordpress conditional adsense


【解决方案1】:

这应该注入 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>';' 

【讨论】:

  • *注意,如果您的帖子少于 4 个,则不会出现 Adsense。这是一个问题吗?
  • 这不是问题,在这样的情况下呢:'echo '
    '; while (have_posts()): the_post(); echo child_classic_blog_render(get_the_ID(), 35);结束;回声'
    ';'
猜你喜欢
  • 2013-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-02
  • 2015-05-14
  • 1970-01-01
  • 1970-01-01
  • 2020-03-29
相关资源
最近更新 更多