Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Hardcode Adsense code into post #1 and post #3
dzchimp Offline
Junior Member
**
Posts: 5
Joined: Nov 2011
Post: #1
Hardcode Adsense code into post #1 and post #3
I would like to know how to modify templates, to add manually Adsense <script> </script> codes specifically into the first and third post displayed on any page within a thread.

I have tried using the Conditionals plugin to see whether the post number is #1, and if so, it displays Adcode1, if it is post #3, then Adcode2.

There is a problem. I want ads to display on page 2, 3 etc too. If I got for the code which checks post number, then the ads display only on page 1!, I want them on subsequent pages too, serially on the first and third post on every page.

Here's the code I have tried so far.

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<if $postcounter == '2' then>
<tr><div align="center">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-";
/* InthreadPost#2 */
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>
</div>
</tr>
</if>

<if $postcounter == '3' then>
<tr>
<div align="center">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-cy1";
/* Inpost#1 */
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>


This displays ads on Post #1 and Post #2 of page 1. I want ads on Page 2, 3 etc (all pages)

(This post was last modified: 11-20-2011 03:59 PM by dzchimp.)
11-20-2011 03:58 PM
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: Hardcode Adsense code into post #1 and post #3
You could just subtract the page*perpage from the postcounter, though I don't know how accurate that is.

My Blog
11-20-2011 05:00 PM
Find all posts by this user Quote this message in a reply
dzchimp Offline
Junior Member
**
Posts: 5
Joined: Nov 2011
Post: #3
RE: Hardcode Adsense code into post #1 and post #3
Maybe there is a string that handles the postnumber of the first displayed post in a page? In that case I could add the required number to it, then do an if like I did previously..

Where can I get full documentation of the if plugin?
11-20-2011 05:03 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: Hardcode Adsense code into post #1 and post #3
I don't believe so.  The <if> is pretty much your standard PHP if in a slightly different syntax.

The postbit code is in inc/functions_post.php if you want to look at it.

Probably just do something like:

Code:
<if in_array($postcounter - $mybb->settings['postsperpage']*($page-1), array(1,3)) then>


My Blog
11-20-2011 07:43 PM
Find all posts by this user Quote this message in a reply
terrymason Offline
Junior Member
**
Posts: 1
Joined: Dec 2011
Post: #5
RE: Hardcode Adsense code into post #1 and post #3
This will display an ad on every 3rd post.  I believe that google will only let you show 3 ads (or link units) per page, and will just not show more ads after that.  The modulus operator gives the remainder of the division, so $postcounter % 2 is the amount left over when dividing by 2

Code:
1
2
3
4
5
6
7
<if $postcounter %2 == 0 then>
<tr><div align="center">

<!--adsense code-->

</div></tr>
</if>




I personally don't like showing too many ads to members, so use the code below.  It says that if the user is an admin or a guest then show them the ads

Code:
1
2
3
4
5
6
7
8
9
<if $postcounter %2 == 0 then>
<if $mybb->user['usergroup'] == '1' OR $mybb->user['usergroup'] == '4' then>
<tr><div align="center">

<!--adsense code-->

</div></tr>
</if>
</if>

(This post was last modified: 12-01-2011 05:33 AM by terrymason.)
12-01-2011 05:32 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #6
RE: Hardcode Adsense code into post #1 and post #3
"%2" will be for every second post I believe.
So if $postcounter is 1 for the first post, it will show on the 2nd, 4th, 6th etc post.

My Blog
12-01-2011 08:55 AM
Find all posts by this user Quote this message in a reply
dzchimp Offline
Junior Member
**
Posts: 5
Joined: Nov 2011
Post: #7
RE: Hardcode Adsense code into post #1 and post #3
What's the format of elseif with this plugin?
12-08-2011 08:38 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #8
RE: Hardcode Adsense code into post #1 and post #3

Code:
1
2
3
4
5
6
7
8
9
<if condition then>
...
<elseif condition then>
...
<elseif condition then>
...
<else>
...
</if>

All parts except the first and last lines being optional.


My Blog
12-08-2011 08:49 AM
Find all posts by this user Quote this message in a reply
dzchimp Offline
Junior Member
**
Posts: 5
Joined: Nov 2011
Post: #9
RE: Hardcode Adsense code into post #1 and post #3
Thanks for all your help. Solved it. Smile

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<if in_array($postcounter - $mybb->settings['postsperpage']*($page-1), array(1,3)) then>
<span style="margin-left: 25%; margin-right: 25%;\padding: 1px;">
<if in_array($postcounter - $mybb->settings['postsperpage']*($page-1), array(1)) then>
	<tr><div align="center">
	<script type="text/javascript">
	/* ad #1*/
	
	</script>
	<script type="text/javascript"
	src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
	</script>
	</div></tr>
<elseif in_array($postcounter - $mybb->settings['postsperpage']*($page-1), array(3)) then>
	<tr><div align="center">
	<script type="text/javascript">
/* add #2 */
	</script>
	</div></tr>
</if>
 </span>
 </if>

12-08-2011 08:58 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: