【问题标题】:Inserting ad code after the first loop在第一个循环之后插入广告代码
【发布时间】:2015-04-06 09:42:56
【问题描述】:

如何仅在插入 <br style="clear: both" /> 后的第一个完整行之后才插入 Google 广告代码,然后允许循环继续添加 <br style="clear: both" />,而不添加广告代码,直到完成。

这是我正在尝试编辑的代码,目前它会一直处理,直到显示所有图像。每行有 4 张图片宽,在第四张图片之后插入 <br style="clear: both" /> 并开始下一行。

    <?php if ($number_of_columns > 0 && empty($show_all_in_lightbox)): ?>
        <?php if ((($i + 1) % $number_of_columns) == 0 ): ?>
            <br style="clear: both" />
        <?php endif; ?>
    <?php endif; ?>

这里是声明

<?php for ($i=0; $i<count($images); $i++):
       $image = $images[$i];
       $thumb_size = $storage->get_image_dimensions($image, $thumbnail_size_name);
       $style = isset($image->style) ? $image->style : null;

【问题讨论】:

    标签: php adsense


    【解决方案1】:

    假设 $i 代表图像数组中的索引,您可以添加另一个 if 语句来检查它是否是第一行,如下所示。

    <?php if ($number_of_columns > 0 && empty($show_all_in_lightbox)): ?>
        <?php if ((($i + 1) % $number_of_columns) == 0 ): ?>
            <br style="clear: both" />
            <?php if (($i + 1) == $number_of_columns): ?>{insert your ad code}<?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多