1. XenForo 1.5.14 中文版——支持中文搜索!现已发布!查看详情
  2. Xenforo 爱好者讨论群:215909318 XenForo专区

交流 石头希望帮忙弄个插件 Responsive AdSense

本帖由 magicdroidx2016-06-20 发布。版面名称:XenForo中文版

  1. magicdroidx

    magicdroidx VIP会员

    注册:
    2016-01-01
    帖子:
    5
    赞:
    0
    如题,感谢万分!
     
  2. admin

    admin 管理员 管理成员

    注册:
    2011-11-01
    帖子:
    3,671
    赞:
    2,425
    是这个吗?https://xenforo.com/community/resources/responsive-adsense.2084/

    The items highlighted in red are the important bits of code which are in addition to regular AdSense code.
    The items highlighted in blue are the different ad slots.

    The first is using the ad_thread_list_below_stickies template.
    代码:
    <xen:hook name="ad_thread_list_below_stickies" />
    
    <xen:if is="!{$visitor.user_id}">
        <xen:if is="{$stickyThreads}">
            <div style="text-align: center; padding: 8px 0 4px 0; border-bottom: 1px solid @primaryLighterStill">
                <script type="text/javascript">
                google_ad_client = "ca-pub-id";
                width = document.documentElement.clientWidth;
                /* Thread List Below Stickies Responsive 2 */
                google_ad_slot = "123456890";
                google_ad_width = 320;
                google_ad_height = 50;
                    if (width > 483) {
                    /* Thread List Below Stickies Responsive 1 */
                    google_ad_slot = "123456890";
                    google_ad_width = 468;
                    google_ad_height = 60;
                    }
                        if (width > 743) {
                        /* Thread List Below Stickies */
                        google_ad_slot = "123456890";
                        google_ad_width = 728;
                        google_ad_height = 90;
                        }
                </script>
                <script type="text/javascript"
                src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                </script>
            </div>
        </xen:if>
    </xen:if>
    What the above code will do is display the advertisements as follows:
    • Browser width 483 and below - 320x50
    • Browser width 484 to 743 - 468x60
    • Browser width 744 and above - 729x90
    So as you can see, as the browser window increases (or reduces) in width, different ad slots are served.

    Here's another more complex example using the ad_message_below template:

    代码:
    <xen:hook name="ad_message_below" />
    
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND {$thread.reply_count} > 0">
        <xen:if is="!{$visitor.user_id}">
            <li class="message">
                <div class="messageUserInfo" itemscope="itemscope" itemtype="http://data-vocabulary.org/Person">
                    <div class="messageUserBlock">
                        <div class="avatarHolder">
                            <span class="helper"></span>
                            <xen:avatar user="$visitor" size="m" img="true" />
                        </div>
                        <h3 class="userText">
                        <span style="font-weight: bold">Google AdSense</span>
                        <em class="userTitle" itemprop="title">Guest Advertisement</em>
                        </h3>
                        <span class="arrow"><span></span></span>
                    </div>
                </div>
                <div class="messageInfo primaryContent">
                    <div class="messageContent">
                        <article>
                            <blockquote class="messageText ugc baseHtml">
                                <script type="text/javascript">
                                google_ad_client = "ca-pub-id";
                                width = document.documentElement.clientWidth;
                                /* Message Below Responsive 2 */
                                google_ad_slot = "1234567890";
                                google_ad_width = 320;
                                google_ad_height = 50;
                                    if (width > 619) {
                                    /* Message Below Responsive 1 */
                                    google_ad_slot = "1234567890";
                                    google_ad_width = 468;
                                    google_ad_height = 60;
                                    }
                                        if (width > 879) {
                                        /* Message Below */
                                        google_ad_slot = "1234567890";
                                        google_ad_width = 728;
                                        google_ad_height = 90;
                                        }
                                </script>
                                <script type="text/javascript"
                                src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                                </script>
                                <br /><br /><label for="LoginControl"><span style="font-weight: bold; color: #004400"><a href="login/" class="concealed noOutline">Log in or Sign up</a></span></label> to hide all adverts.
                            </blockquote>
                        </article>
                    </div>
                </div>
            </li>
        </xen:if>
    </xen:if>
    So anything up to 619px, the 320x50 ad slot will be served.
    Between 620px and 879px, the 468x60 ad slot will be served.
    At widths of 880px and above, the 728x90 ad slot will be served.

    These trigger points are based on my style which includes the margin, padding, avatar block width and message content margin, which is 8+120+16+advert width+8.
    So for the 468 wide advert it requires a width of 8+120+16+468+8 = 620.
    Hence why the trigger point is width > 619.

    These trigger points will vary from style to style - you will have to work them out.
     
  3. magicdroidx

    magicdroidx VIP会员

    注册:
    2016-01-01
    帖子:
    5
    赞:
    0
    是的
     
正在加载...