MyBB Hacks

Full Version: conditional statement for adsense
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to get adsense to appear after the last post on a page, but only if the page has 3 or more posts.

Here is what I have so far at the bottom of the postbit template:

Code:
<if ($postcounter - 1) % ($mybb->settings['postsperpage']) == "2" then>
adsense code here
</if>


This shows an ad after the 3nd post only, but I can not figure how to make it show it AFTER the last post, IF there are 3 or more posts.

Example: If a page had 8 posts, it would show the ad after the 8th post, if it had 4 posts, it would show it after the 4rd, if it had 10 posts, it would show it after the 10th post.  Note that that is the number of posts per page and not per thread.

$postcounter refers to the current post's #.
If you want the total number of posts, you should use $thread['replies']

But if all you want to do is put it after all the posts, don't put the code in the postbit template - try the showthread template instead.
(05-21-2011 06:30 PM)ZiNgA BuRgA Wrote: [ -> ]$postcounter refers to the current post's #.
If you want the total number of posts, you should use $thread['replies']

But if all you want to do is put it after all the posts, don't put the code in the postbit template - try the showthread template instead.

Thank you for your reply. I want it under all the posts on each page, but ONLY if there are 3 or more posts on the page. I had it on the showthread template but it would appear even if there was only 1 or 2 posts.
Try this condition in your showthread template:

Code:
<if ($GLOBALS['postcount'] - $GLOBALS['start']) >= X then>
Ads Codes Here
</if>


Replace X with the minimum post. Need to refresh the page.

Excellent! This works exactly as I needed, thank you very much.
Reference URL's