Adsense advert after first post?

JamesBrown

Well-known member
I have found that an advert after the first post is one of the best adsense earners. can someone post an idiots guide to achieving this with with XF. Thanks in anticipation.
 
No, just the ad_ templates.

The above is achieved very simply, like so:
Code:
<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">
                <div class="messageUserBlock">
                    <div class="avatarHolder" style="height: 102px; width: 102px">
                        <span class="helper"></span>
                        <img src="http://cliptheapex.com/data/avatars/m/0/2.jpg" alt="Avatar" height="96px" width="96px" style="border: 1px solid #C0C0C0; padding: 2px" />
                    </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-######";
                            /* Message Below */
                            google_ad_slot = "######";
                            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>

Why not combining the conditions into:

Code:
<xen:hook name="ad_message_below" />
 
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND {$thread.reply_count} > 0 AND !{$visitor.user_id}">
  <li class="message">
            <div class="messageUserInfo">
                <div class="messageUserBlock">
                    <div class="avatarHolder" style="height: 102px; width: 102px">
                        <span class="helper"></span>
                        <img src="http://cliptheapex.com/data/avatars/m/0/2.jpg" alt="Avatar" height="96px" width="96px" style="border: 1px solid #C0C0C0; padding: 2px" />
                    </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-######";
                            /* Message Below */
                            google_ad_slot = "######";
                            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>
 
Ahh its working now but one last problem its still only showing to guests. Not sure if you spotted my other post i didn't know what you meant on how to make all usergroups see the advert and not just guests?
 
Erm... I asked how to make everyone be able to see it and you said:
Remove the guest conditional <xen:if is="!{$visitor.user_id}"> ... </xen:if>

Which i said i didn't understand then i went on and asked if you could do various things with the code in which you then posted another code in which i have now used and as i have said above it works but it still can only be seen by guests. No other codes have been added since which i havnt tried.
 
I definitely thought about this method, my concern is many visitors wouldn't like adverts after first post, wouldn't it be deceiver? You know, they expect the response would be second post. Somewhere few years ago, I visited other forum and found strange of second post advertising in every pages. Do you think it is annoying?
 
Thanks for taking the time to get back to me. I really dont know what the problem is its not showing at all now to guests or visitors :( really strange.
 
I think you must have scared it into working lol, i have just left the code in place for a few minutes and gone back to the page and its now showing yey at last.
Thanks for sticking with me Brogan we got there in the end lol.
 
@Brogan You had helped me a while back with this code:

Code:
<xen:hook name="ad_message_below" />
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$visitor.user_id}">
<div style="float: right; margin-top:15px; margin-right: 40px;">
AD CODE
</div></xen:if>

I had this originally within ad_message_body it showed within the body of the first post on every page of a thread.

Upon concerns of Google's 'top heavy' algo, I've moved it down to ad_message_below. Right now, it shows below the first message on each page of a discussion.

There are a few refinements I'd like to make, but not sure if it's possible.

  • Have ad show after the second post on each page within a thread.
  • Ad will not show up on threads with no responses. (hoping the first will solve that)
Thanks!
 
Replace the conditional statement with this:
Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 1 AND {$thread.reply_count} > 0 AND !{$visitor.user_id}">
 
Replace the conditional statement with this:
Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 1 AND {$thread.reply_count} > 0 AND !{$visitor.user_id}">

Perfect. Thank you sir! Trying to push more content up to top of the page. Using Google Webmasters, I found that by having ad_message_body, I technically had two ads showing before any content. At least according to the Googlebot. I wish Google was more transparent about ad placement. Adsense will tell you one thing, but search gives you vague direction on what isn't acceptable. In any event, thanks again for your help. It's much appreciated.
 
Responsive version working in XF 1.2 Beta 5

HTML:
<xen:hook name="ad_message_below" />
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND {$thread.reply_count} > 0">
    <li class="message">
        <div class="messageUserInfo">
            <div class="messageUserBlock">
                <xen:if is="@enableResponsive">
                <div class="avatarHolder" style="height: 54px; width: 54px">
                    <span class="helper"></span>
                    <img src="http://cdn.z22se.com/xenforo/avatars/avatar_s.png" alt="Avatar" height="48px" width="48px" style="border: 1px solid #C0C0C0; padding: 2px" />
                <xen:else />
                    <div class="avatarHolder" style="height: 102px; width: 102px">
                    <span class="helper"></span>
                    <img src="http://cdn.z22se.com/xenforo/avatars/avatar_l.png" alt="Avatar" height="96px" width="96px" style="border: 1px solid #C0C0C0; padding: 2px" />
                    </xen:if>
                </div>
                <h3 class="userText">
                <span style="font-weight: bold">CUSTOM NAME</span>
                <em class="userTitle" itemprop="title">CUSTOM TITLE</em>
                </h3>
                <span class="arrow"><span></span></span>
            </div>
        </div>
        <div class="messageInfo primaryContent">
            <div class="messageContent">
                <article>
                    <blockquote class="messageText ugc baseHtml">
                        <center>YOUR ADD HERE</a></center>
                    </blockquote>
                </article>
            </div>
        </div>
    </li>
</xen:if>

2013-07-12 06.37.21.webp
 
This is a better version. Uses the guest avatar, so it's using the full responsive CSS available.

HTML:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND {$thread.reply_count} > 0">
    <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">NAME</span>
                <em class="userTitle" itemprop="title">TITLE</em>
                </h3>
                <span class="arrow"><span></span></span>
            </div>
        </div>
        <div class="messageInfo primaryContent">
            <div class="messageContent">
                <article>
                    <blockquote class="messageText ugc baseHtml">
                        YOUR ADVERT
                    </blockquote>
                </article>
            </div>
        </div>
    </li>
</xen:if>
 
To follow on from Matt's post above, this is what I now have in ad_message_below:

HTML:
<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 at widths of 880px and above, the 728x90 ad will be displayed.
Between 620px and 879px, the 468x60 ad will be displayed.
Anything up to 619px, the 320x50 ad will be displayed.

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.
 
Back
Top Bottom