Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 conditional statement for adsense
mac834 Offline
Junior Member
**
Posts: 3
Joined: May 2011
Post: #1
conditional statement for adsense
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.

05-21-2011 11:30 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: conditional statement for adsense
$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.

My Blog
05-21-2011 06:30 PM
Find all posts by this user Quote this message in a reply
mac834 Offline
Junior Member
**
Posts: 3
Joined: May 2011
Post: #3
RE: conditional statement for adsense
(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.
05-21-2011 08:35 PM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #4
RE: conditional statement for adsense
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.


05-22-2011 03:10 AM
Find all posts by this user Quote this message in a reply
mac834 Offline
Junior Member
**
Posts: 3
Joined: May 2011
Post: #5
RE: conditional statement for adsense
Excellent! This works exactly as I needed, thank you very much.
05-24-2011 07:33 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: