[OzzModz] Google Adsense tips and visual overview of ad positions

[OzzModz] Google Adsense tips and visual overview of ad positions

Has anyone turned the "After First, Middle and Before Last Post" option into "After First, Middle and After Last Post" and would care to share? I just played with it for a bit and couldn't get it to display.
Wondering why nobody replied? That's because you'll get a headache making these unreadable conditionals :p
Give this one a try:
Code:
<xf:if is="in_array($post.position % $xf.options.messagesPerPage, [0,($xf.options.messagesPerPage / 2) - 1]) OR $post.position % $xf.options.messagesPerPage + 1 == count($__globals.posts) AND count($__globals.posts)>4">
 
Is there an existing container that places ads in that section at all? I will just use that one as long as it puts ads in between the new profile posts
 
This can be done without an addon now. Just need to use this code:

Code:
<xf:if is="$__globals.firstUnread.post_id == $post.post_id">
    <div style="margin:3px 0 3px 0;">
    ### your ad code ###
    </div>
</xf:if>
Is there a way to make this work and not show up below the two first posts and not the two last post? Having banners there already and want to keep them as this banner only shows for logged in users.
 
Is there a way to make this work and not show up below the two first posts and not the two last post? Having banners there already and want to keep them as this banner only shows for logged in users.
@Mr. Jinx do you have any suggestions about the above?
 
Please try this one @ge66 and let me know if it works:
Code:
<xf:if is="$__globals.firstUnread.post_id == $post.post_id AND $post.position % $xf.options.messagesPerPage > 1 AND (count($__globals.posts) - $post.position % $xf.options.messagesPerPage) > 2">
    <div style="margin:3px 0 3px 0;">
    ### your ad code ###
    </div>
</xf:if>
 
Please try this one @ge66 and let me know if it works:
Code:
<xf:if is="$__globals.firstUnread.post_id == $post.post_id AND $post.position % $xf.options.messagesPerPage > 1 AND (count($__globals.posts) - $post.position % $xf.options.messagesPerPage) > 2">
    <div style="margin:3px 0 3px 0;">
    ### your ad code ###
    </div>
</xf:if>
Thank you, I have done some testing and I think it is working.
 
I am trying to create a "First Post" conditional statement to show an ad in New Threads widget on our front page. Basically looking to add a banner after the first post in the New Threads widget, similar to the After First Post condition outlined in this guide:

After First Post
This conditional will show an ad after the first post if there are 2 or more posts on the page.
Position = "Post: Below message container"
Code:
<xf:if is="$post.position % $xf.options.messagesPerPage==0 AND count($__globals.posts)>0">
    <div style="margin:3px 0 3px 0;">
    ### your ad code ###
    </div>
</xf:if>


I've created a recent_threads_below_content Advertising position and added it to the New Threads widget template:

Code:
<div class="blocks" {{ widget_data($widget) }}>
    <xf:if is="$showExpandedTitle">
        <h2 class="blocks-header">
            {$title}
        </h2>
    </xf:if>
    <xf:foreach loop="$threads" value="$thread">
        <xf:set var="$post" value="{$thread.FirstPost}" />
        <div class="block">
            ...[snip]...
        </div>
        <xf:ad position="recent_threads_below_content" arg-post="{$post}" />
    </xf:foreach>
</div>

I can't seem to find the right conditional statement to duplicate the $post.position in the original for the New Threads widget. I see when dumping $post variables they are "null". What am I missing on how to accomplish this?

Appreciate any help/info on this.
 
Why does count($__globals.posts)>4 doesn't work on thread_view template?
Thanks!
That is because there are no posts in thread_view, so there is no variable $__globals.posts.
I see this same sort of issue was asked/answered previously in this same thread. Is there a way to add a variable to the New Threads widget template so it can be called for post count conditionals? @Mr. Jinx? (This is getting beyond my skill level.)

Thanks.
 
I think this should work. Quick and dirty... if some else know a better solution?
You'll have to make these modifications in widget_new_threads and this example assumes that you are using the 'expanded' view.
This basically adds a counter, and only displays 'ad code' when it equals 1.

Find:
Code:
            <xf:foreach loop="$threads" value="$thread">
                <xf:set var="$post" value="{$thread.FirstPost}" />

Replace with:
Code:
            <xf:foreach loop="$threads" value="$thread" i="$i">
                <xf:set var="$post" value="{$thread.FirstPost}" />

Find:
Code:
                </div>
            </xf:foreach>
        </div>
    </xf:if>
</xf:if>

Replace with:
Code:
                </div>
                <xf:if is="$i == 1">ad code</xf:if>
            </xf:foreach>
        </div>
    </xf:if>
</xf:if>
 
  • Like
Reactions: jca
Thanks @Mr. Jinx -- awesome work. Much appreciated.

Rather than put the ad code in the template as your example, I put it in the previously mentioned ad position (in the same spot in the template) and used this to call it from the Advertising section:
Code:
<xf:if is="$__globals.i==1">ad code</xf:if>

Hope this helps someone else out, such as @rdn who asked previously in this thread.

Thanks again!
 
Hello! And thanks for this awesome tips. Very useful for sure.

One question, how do i make this code:
Code:
<xf:if is="in_array($post.position % $xf.options.messagesPerPage, [0,($xf.options.messagesPerPage / 2) - 1,$xf.options.messagesPerPage - 2]) AND count($__globals.posts)>4">
    <div style="margin:3px 0 3px 0;">
    ### your ad code ###
    </div>
</xf:if>

Just for the MIDDLE position of the thread instead of first, middle and last?

I have a specif ad for the last post and another one after the first post, but i want one specific just in the middle too.

Can we make it happen?

Thank you very much.
 
I have a specif ad for the last post and another one after the first post, but i want one specific just in the middle too.
You can use this one for the middle position. It will only show if there are 3 posts or more, but you can change it if you like:

Code:
<xf:if is="$post.position % $xf.options.messagesPerPage==ceil(count($__globals.posts) / 2) - 1 AND count($__globals.posts)>2">
    <div style="margin:3px 0 3px 0;">
    ### your ad code ###
    </div>
</xf:if>
 
Hey @Mr. Jinx ! I don't remember if I said thank you for this grate tutorial, so thank you just in case. )
Could you please advice what would be conditional for the first page in a forum node (hide on further pages in that forum)?
Thanks in advance.
 
Top Bottom