Friday, 20 April 2012

Place Google ads inline your blog post using XsltPlugin

Create an xml file where you will be keeping the adsense code for your ads. Between the CDATA sections you should put your adsense code for each ad. Give it a name ie. “ads.xml” and save it. It should be similar to this:

<?xml version="1.0" encoding="utf-8" ?> 
<![CDATA[<script type="text/javascript"><!--
google_ad_client = "ca-pub-DDDDDDDDDD";
/* Prog, 234x60, created 1/16/11 */
google_ad_slot = "DDDDDDDDDD";
google_ad_width = 234;
google_ad_height = 60;
<script type="text/javascript"


Create a new file call it ie. “ InsertAd.xslt” and place inside the code below:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"

<xsl:output method="html"/>

<xsl:template match="/">
<div class="" style="text-align: center ">
<!--<xsl:call-template name="uListAds"/>-->
<xsl:value-of select="/ads/ad[1]" disable-output-escaping="yes"/>

<xsl:template name="uListAds">
<xsl:for-each select="ads/ad">
<li class="">

<xsl:value-of select="." disable-output-escaping="yes"/>


Using the Window Live Writer and the XsltPlugin select the “ads.xml” and the “InsertAd.xslt” file and click to insert the content inline your blog post maybe at the begining, in the middle or at the end.
The xslt template above will select the first ad from your xml file and center align it in the post. If you want a different ad you should change the index ie.
<xsl:value-of select="/ads/ad[2]" disable-output-escaping="yes"/>
in the “InsertAd.xslt”. Or if you want a list of ads you can comment out the above and comment in the “uListAds” template and modify it according to your need ie. vertical/horizontal placement. However be cautious with adding many ads on page I think there is a limit.
The ad you see in this post has been inserted using this method.


No comments:

Post a Comment