Saturday, December 16, 2006

Adsense inside your posts and only on post (item) pages

Loui$$ from Blogging Secret just asked me how I was displaying adsense ads only on post (item) pages and inside the post i.e. in the beginning and the end of each post. For this I use the same if statements from my hack Display widgets only on pages you prefer but widget are not involved in this one as widgets cannot go inside a post.

First let me acknowledge the sources from which I learnt some essential adsense tricks for Blogger Beta:

1. Using adsense code in beta template by Loui$$.
2. Using adsense in posts by Deniz.

I recommend checking those out before proceeding with this hack. As always, please back-up your template before proceeding with this hack as you will be modifying some important portions of your template. Now for the hack. Simply look for:

<p><data:post.body/></p>

in your template's <div class='post'> section and replace it with the code given in code boxes below:
([Your Adsense] in the each of codes given below must be replaced with the adsense code of your choice)

1. This code:
(if you are not using any hacks like peek-a-boo posts, selective expandable posts or peek-a-boo on label, archive and search pages)


<b:if cond='data:blog.pageType == "item"'>
<p><table align='center'><tr><td>
<center>[Your Adsense]</center></td></tr></table>
<data:post.body/><table align='center'><tr><td>
<center>[Your Adsense]</center></td></tr></table></p>
<b:else/>
<p><data:post.body/></p>
</b:if>


2. This code in bold-italic (If you are using Peek-a-boo posts hacks)
(If you are also using the peek-a-boo on label and search pages hack, then there may be some confusion regarding which <p><data:post.body/></p> must be replaced with the code given below. Therefore, I have included the peek-a-boo code as well so that you can easily locate the correct instance of data:post.body/ in your template.)


<div class='post-body' expr:id='"post-" + data:post.id'>
<b:if cond='data:blog.pageType == "item"'>
<p><table align='center'><tr><td>
<center>Your Adsense</center></td></tr></table>
<data:post.body/><table align='center'><tr><td>
<center>Your Adsense</center></td></tr></table></p>

<b:else/>
<style>#fullpost {display:none;}</style>
<p><data:post.body/></p>
<span id='showlink'>
<p><a expr:onclick='"javascript:showFull(\"post-" + data:post.id + "\");"' href='javascript:void(0);'>Continue reading...</a></p>
</span>
<span id='hidelink' style='display:none'>
<p><a expr:onclick='"javascript:hideFull(\"post-" + data:post.id + "\");"' href='javascript:void(0);'>Excerpts only...</a></p>
</span>
<script type='text/javascript'>checkFull(&quot;post-&quot; + &quot;<data:post.id/>&quot;)</script>
</b:if>
<div style='clear: both;'/> <!-- clear for photos floats -->
</div>


3. This code in bold-italic (If you are using selective expandable posts hack)


<div class='post-body' expr:id='"post-" + data:post.id'>

<b:if cond='data:blog.pageType == "item"'>
<style>#fullpost{display:inline;}</style>
<p><table align='center'><tr><td>
<center>[Your Adsense]</center></td></tr></table>
<data:post.body/><br/>
<table align='center'><tr><td><center>
[Your Adsense]</center></td></tr></table></p>


<b:else/>
<style>#fullpost{display:none;}</style>

<p><data:post.body/></p>

<span id='showlink'>
<a expr:href='data:post.url'>Read More......</a>
</span>
<script type='text/javascript'>
checkFull(&quot;post-&quot; + &quot;<data:post.id/>&quot;);
</script>
</b:if>
<div style='clear: both;'/> <!-- clear for photos floats -->
</div>

Hope this becomes the tipping point in your adsense revenues graph :D

28 comments:

LOUI$$ said...

Bro, i have show your tutorial in my blog and link back to you, wish we can help others too!

Vivek Sanghi said...

Thanks Loui$$!

EscapeGames24 said...

Hi Vivek, thanks for this post, but i have a problem about that. When i putting ads code in my testing blog nothing showed about adsense. So i have changed default template but again nothing seen. However, when i put text it seen good. What can be problem about that. Thanks again;)

Vivek Sanghi said...

Hello escaper. Your profile was inaccessible so I could not look at the source code of your blogs. I am guessing that you are using the adsense code as it is, without making the modification that Loui$$ has suggested to display the ads. Just check out his blog here to learn how to get the code to display what it should. Let me know if you still face any problems. Cheers!

EscapeGames24 said...

Thanks again Vivek, i forgot about doing modification, now it is ok;)

Bambang Aroengbinang said...

Hi Vivek,

I found that there two data:post.body

div class='post-body'
b:if cond='data:blog.pageType == "item"'

style.fullpost display:inline;
/style

p data:post.body/ /p
b:else/
style.fullpost display:none; /style

p data:post.body/ /p

a expr:href='data:post.url' Read More...... /a
/b:if

Which one shall I replace?

Since I have used louiss hack on ads below post title, is there any modification needed?

Thanks!

Vivek Sanghi said...

Hello aroengbinang. From the code that you gave in your comments, it appears that you are using a peek-a-boo type post hack from Ramani/Hans. In that case you have to use the code I have given on the first data:post.body that appears immediately after:

b:if cond='data:blog.pageType == "item"'

With Louiss's hack you are displaying ads under the heading on the main page, however with my hack your ads will display only on the individual post pages. Both the hacks cannot be used together. So its up to you to decide where you want to display the ads.

In case you choose to display ads only on the post pages, you can use your side bars to display ads on the main page and also use the space above the post section to display text-link like I have done.

Note that the code I have given also displays ads below the post heading as well as above the post footer (after the post finishes). See the example code in third code box for more details. Hope this helps.

Bambang Aroengbinang said...

Hi Vivek,

Thank you so much for taking the time. Appreciate it very much.

Really need advise, whether to put both of luoi$$'s hack and yours will be a violation of adsense policy, other than it maybe considered excessive to the readers.

Kindly check at http://aroengbinang.blogspot.com/2006/12/rise-and-fall.html as an example.

Cheers

Vivek Sanghi said...

Hello aroengbinang. Google adsense says that there should not be more that 3 ads on any webpage. You have three ads on each of your post pages which is just fine. However, having two rectangular ads near the top of the post is a wastage in my opinion. You might want to put a large rectangle like I have on my post pages (but make sure that you do it only for the post pages). Basically you can do some thing like this:

Have Louiss's hack using the normal rectangle (that you are using now) displayed only on blog main page by enclosing it in the following if condition:

<b:if cond='data:blog.homepageUrl == data:blog.url'>


</b:if>


And in my hack just replace the current adsense code with the code for a larger rectangle. Once you do that, only for your post pages you can add another ad or linklist if there are none currently like say in the sidebar.

Note that you can have only one Google link unit (like the one i have on the top of my post section and search box) per page.

Googlr said...

hi vivek,
I am new to your blog and to be honey it is kind of too much to go through.
can this hack work in old blogger.

Bambang Aroengbinang said...

Hi Vivek, thanks!

I agree and follow your advise to put Louiss' hack on the main page only.

I wish adsense has a double layer ads similar with your hack + louiss' hack in post pages that I used before.

Just need one more advise: how can i put adsense in post pages right after the neo-counter at the lower right as in http://aroengbinang.blogspot.com/2007/01/a-collection-of-humor.html?

Thanks again!
Cheers,

Unknown said...

hi..
1stly i would like to thank u and louss for hackin blogger beta so much easier ...
however i am facing problems with adsense on my blog ..
i am not able to align the ads to the left (they r in the center)..
also i am facing problems with the google link ads .. they are not being displayed (i added them through add a page element on my sidebar )
plz help...

Unknown said...

one mor thing ...
i am not able to filter the ads being displayed ..
competitive ad filter is not helping
plz suggest ..

Anonymous said...

Hi Vivek!
I am trouble with this hack!
I am using Ramani´s and Hans Super Peek-a-boo hack and I do not get it working alhought I have add and deleted it couple times it!

Anonymous said...

Sorry if this comes two times!

Here is my blog
binäärijärjestelmä Could you check whats wrong with this hack wich I add there. I use Ramani´s and Hans super peek-a-boo hack

Anonymous said...

Never mind about those questions!
I got it working now

Prince John said...

Hi Vivek,

It works well, especially after removing the HTML comment tag ( < ! - -) from within the adsense code. Still worrying if what i have done is adsense TOS violation

Elmer said...

Thanks Vivek, great tutorial, but can't seem to follow-up on this one. I Keep losing it.

I would appreciate it if you could visit me http://kabayan-junction.blogspot.com, i would want your help about:

1. How to put my adsensse on every post if it's possible.

2. How to expand the size of the template, it seem the images keep adjusting.

Hope this is not to much.

Thankz

Vivek Sanghi said...

Hello E Akino. Welcome to Stubborn Fanatic.

1. Google does not allow its users to have more than 3 or 4 ads on a single page. (apologies for not giving the exact figure and I have not been in touch with the blogging world)

2. I not sure if I understood you correctly. However, here is my suggestion: If you want to increase the main wrapper size (such that the post section has more width), you can do that by changing the pixel values of the width under the main wrapper and outer wrapper (in the template HTML). A good fit can be determined using trail and error method.

If you want your blog to work fluid style i.e. adjust and fill screen space according to end user's resolution settings, then check out tutorials on the same at:

beautifulbeta.blogspot.com or bloggeruniversity.blogspot.com

Regards

Vivek

hh said...

Hi Vivek

Great post you have here. I have been trying to follow your hack as well the changing the Adsense code. However, it doesn't seem to work on my site. Could you please have a look? The site is http://indiapr.blogspot.com

best, HH

hh said...

hi vivek...sat for an hour and finally figured that I put the code on the wrong place :-) great hack...keep it up.

IIM INDIA said...

hello vivek sanghi
your blog is really a surprise gift to the new bloggerers. you heck adsense in your posts is really unbelievable item.
keep it up

with best wishes
moneyindia123

Gopinath M said...

Hi Vivek,
When I tried implementing the same, the ads background and border are changed. Ads are displayed with in a black table and background color is random. If you have any idea regarding this problem, please let me know at gopinahtmunisifreddy@gmail.com. My blog is mgopinath.blogspot.com

Unknown said...

I have read and applied the hack. It works perfectly! Thanks for sharing this info...

lol at first I was shocked because I saw [Your Adsense] instead of the actual ad but I forgot I have not posted the adsense code yet. hehe

Thanks once again. ^_^

Unknown said...

Hi! I have 5 post on my manin blogger page. I want to adsense only below one one main post (Not below all post) Pls tell me how can i do so.

desigal said...

i can`t get it to work on my blog
chek it plz and temme how to implement right side within posts ad


TechnoKudi

Admin said...

http://happyschools.blogspot.com/

Thanks Vivek. Nice site and idea too.

Kash M said...

Hi Vivek,

Excellent posts here by you . I have changed my template and applied post summaries hack to it and then tried to add this hack but it seems like Some other modifications have been already applied to the template which is not allowing adsense ads to appear . What to do in this case ??

Here is the template I am talking about : RD

Other posts @ Stubborn Fanatic

Click here to view all my posts.

Creative Commons License
This work is licensed under a
Creative Commons Attribution-ShareAlike 2.5 License.

However, prior permission is required before you can display any content from this blog on your site. The author reserves the right to demand removal of such content at any time for any reason. (Not applicable for back-linking)
Note: The author is not responsible for any loss of data or damages to your homepage as a result of using the hacks suggested here. Please observe all necessary precautions while modifying template code.

© 2006 Vivek Sanghi a.k.a Stubborn-Fanatic