I have recently moved my blog from community server to dasBlog. While setting up google Adsense ads on the site, I was caught up in a specific requirement as in where to put the ads. Google suggests that for high CTR ratio, ads should be placed just above the content and this left me searching for ways to put adsense in start of First Post's body content.
A simple way to implement this was modify your latest post every time you write a post ... cumbersome huh?? Not only cumbersome, this also invalidates your RSS as the feeds doesn't allow <_SCRIPT_> tag in the XML. Looked around little more thinking that I might not be the first one having this kinda requirement ...but to my disappointment, I couldn't find any such generic way to achieve this...
finally this is what I used as a workaround...I don't claim that this is the best possible way to do it but given my one day old relationship with with dasBlog code....this is the most generic change I could make to have it working for me...(Yes you read it right...there is little code change in newtelligence.DasBlog.Web.Core.dll)..
here is what I did...
- First create a category named "AdPost" and add first post to it.
- Then modify site.config file to add one more element..Look closely for html tags converted to literals...
<InContentAdsense>
<DIV style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FLOAT: right; PADDING-BOTTOM: 5px;PADDING-TOP: 5px">
<SCRIPT type=text/javascript><!--
google_ad_client = "pub-123123123123123123";
google_alternate_color = "FFFFFF";
google_ad_width = 300;
google_ad_height = 250;
google_ad_format = "300x250_as";
google_ad_type = "text";
google_ad_channel ="";
google_color_border = "EEEEEE";
google_color_bg = "FFFFFF";
google_color_link = "355EA0";
google_color_url = "355EA0";
google_color_text = "333333";
//-->
</SCRIPT>
<SCRIPT src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type=text/javascript>
</SCRIPT> </DIV>
</InContentAdsense>
Note: By this change there was some issues with configuration update page which I'll figure out later...
3. Set up thecodebase and add this code and declarition in SiteConfig.cs under project <b>newtelligence.DasBlog.Web.Core</b>
string inContentAdsense = null; //to be added in declarition
public string InContentAdsense {
get { return inContentAdsense; }
set { inContentAdsense = value; }
}
4. In the same project open Macros.cs and modify method ..public virtual Control Items{ ....}
here is the modification....
string cntnt = entry.Content;
if (entry.Categories.IndexOf("AdPost") != -1)
{
entry.Content = requestPage.SiteConfig.InContentAdsense + cntnt;
}
requestPage.ProcessItemTemplate(entry, itemPlaceHolder);
entry.Content = cntnt;
All this and you are ready to roll....Replace your web dll with this dll (newtelligence.DasBlog.Web.Core.dll) and place the config settings in right place.....Now in whichever post you wanna show Adsense, just add it to category AdPost!!!! don't forget to reove other posts from AdPost category as google allowes only 3 instances of an add to be displayed!!! On request I can forward you my copy of newtelligence.DasBlog.Web.Core.dll which would cover step 3 and 4.
Hope there would be a much streamlined solution provided for this in next version of dasBlog...
Cheers!!