【问题标题】:How to show different ad units on different categories如何在不同类别中展示不同的广告单元
【发布时间】:2019-11-11 22:14:52
【问题描述】:

我尝试自行搜索,但找不到合适的答案。

我希望我的 wordpress 网站针对不同类别投放不同的广告单元。例如,我制作了 6 个广告单元,A1 A2 A3 B1 B2 B3。我希望 A1 A2 和 A3 显示在标记为“A 类”的网页上,并且 B1 B2 和 B3 广告单元显示在任何其他类别的网页上。

我将广告代码直接插入到 single.php 的内容循环中。将来,我需要在最多 4 个不同的类别中展示不同的广告单元。

基本上,我正在为广告客户创建特定细分市场的广告单元以进行出价。

提前致谢。

【问题讨论】:

    标签: wordpress categories adsense


    【解决方案1】:

    据我所知,广告客户可以对您的自定义渠道出价,而不是对特定的广告单元。请参阅“Ad placement and how to create it”页面。

    所以,我会这样做:

    • www.google.com/adsense > 我的广告 > 内容 > 自定义渠道

      • 为“A”类别创建一个自定义渠道
      • 一个(“默认”)用于其他 页面(您可以考虑并威胁它为您的“频道 B”)
      • 获取这些频道 ID,例如 "default"="1111111111""A"="2222222222"
    • WordPress 仪表板类别

      • 获取“A”类别ID,例如"A" = 5

    首先,获取当前类别的频道ID:

    <?php
    $google_adsense_custom_channel = "1111111111";
    if ( in_category( 5 ) ) {
      $google_adsense_custom_channel = "2222222222";
    }
    ?>
    

    然后您可以开始打印 ID 为 data-ad-channel 的广告代码:

    <ins class="adsbygoogle"
      style="display:block;"
      data-ad-client="ca-pub-1234"
      data-ad-slot="5678"
      data-ad-channel="<?php echo $google_adsense_custom_channel; ?>"
      data-ad-format="auto"></ins>
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
    

    或者 - 如果您希望您的实现看起来像 like the official AdSense Help Center examples

    <ins class="adsbygoogle"
      style="display:block;"
      data-ad-client="ca-pub-1234"
      data-ad-slot="5678"
      data-ad-format="auto"></ins>
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({
        params: { google_ad_channel: "<?php echo $google_adsense_custom_channel; ?>" }
      });
    </script>
    

    (注意:您需要在频道 ID 周围加上引号,因为频道 ID,例如 0123456789,是字符串。)

    【讨论】:

    • 我认为你的最后一个例子是最好的方法
    猜你喜欢
    • 1970-01-01
    • 2013-04-08
    • 2013-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多