<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Poiesis Web Development &#187; admin</title>
	<atom:link href="http://www.poiesis.co.za/index.php/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.poiesis.co.za</link>
	<description>Because IT matters</description>
	<lastBuildDate>Thu, 18 Aug 2011 16:35:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Adding a short code for Adsense insertion into your post</title>
		<link>http://www.poiesis.co.za/index.php/2009/08/adding-an-adsense-short-code/</link>
		<comments>http://www.poiesis.co.za/index.php/2009/08/adding-an-adsense-short-code/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 13:13:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[functions.php]]></category>
		<category><![CDATA[Google Adsense]]></category>
		<category><![CDATA[is_single()]]></category>

		<guid isPermaLink="false">http://www.poiesis.co.za/?p=122</guid>
		<description><![CDATA[In our last post we looked at hard coding your Google Adsense code to the loop in your index page. That will display Adsense on your home page and your archive pages. In this post we&#8217;ll look at creating a short code to place adsense in your posts on the fly without having to copy [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.poiesis.co.za/wp-content/uploads/2009/06/wordpress-150x150.gif" alt="WordPress" title="WordPress" width="150" height="150" class="alignleft size-thumbnail wp-image-70" />In our last post we looked at hard coding your Google Adsense code to the loop in your index page. That will display Adsense on your home page and your archive pages. In this post we&#8217;ll look at creating a short code to place adsense in your posts on the fly without having to copy and paste your Adsense code. This requires us to add a function and a short code to the <code>functions.php</code> page of your theme.</p>
<p>Don&#8217;t worry, it&#8217;s not complicated at all. Just open your <code>functions.php</code> file in your theme&#8217;s folder and scroll to the bottom of the file. Here we&#8217;ll add the following code:</p>
<p><span id="more-122"></span><code>function adsense( $code ) {<br />
&nbsp; &nbsp; $code = '<br />
&nbsp; &nbsp; &nbsp; &nbsp; Your adsense code<br />
&nbsp; &nbsp; ';<br />
return $code;<br />
}<br />
add_shortcode( 'myAds', 'adsense' );</code></p>
<p>Just insert you adsense code in place of the line: <code>Your adsense code</code>, save the file and upload it to your server. Now, when you&#8217;re writing a post, you can just type the <code>[myAds]</code> short code where ever you want your Adsense to appear.</p>
<p>A word of warning though, you might want to put the short code after the read more quick tag (<code>&lt;!--more--&gt;</code>) or it will show up in the loop and you might end up have more than the permitted number of ads on a page! Alternatively, you can use the <code>is_single()</code> conditional tag in the function to ensure that the Adsense code is only inserted when the single post is viewed, and not when it&#8217;s in the loop. </p>
<p>Just replace the code above with the following code:</p>
<p><code>function adsense( $code ) {<br />
&nbsp; &nbsp; if ( ! is_single() ) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $code = ' ';<br />
&nbsp; &nbsp; } else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $code = '<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Your adsense code<br />
&nbsp; &nbsp; &nbsp; &nbsp; ';<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; return $code;<br />
}<br />
add_shortcode( 'myAds', 'adsense' );</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.poiesis.co.za/index.php/2009/08/adding-an-adsense-short-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Adsense code to your blog</title>
		<link>http://www.poiesis.co.za/index.php/2009/08/adding-adsense-code-to-your-blog/</link>
		<comments>http://www.poiesis.co.za/index.php/2009/08/adding-adsense-code-to-your-blog/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 15:41:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[$wp_query->post_count]]></category>
		<category><![CDATA[Google Adsense]]></category>
		<category><![CDATA[have_posts()]]></category>
		<category><![CDATA[index.php]]></category>
		<category><![CDATA[the loop]]></category>

		<guid isPermaLink="false">http://www.poiesis.co.za/?p=113</guid>
		<description><![CDATA[There are a number of plugins you can use to add Google Adsense to your blog. Unfortunately, most of them have very little flexibility when it comes to the positioning of the ads. But fret not; there are a few hacks you can use to hard code the Adsense code to your blog. These hacks [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.poiesis.co.za/wp-content/uploads/2009/06/wordpress-150x150.gif" alt="WordPress" title="WordPress" width="150" height="150" class="alignleft size-thumbnail wp-image-70" />There are a number of plugins you can use to add Google Adsense to your blog. Unfortunately, most of them have very little flexibility when it comes to the positioning of the ads. But fret not; there are a few hacks you can use to hard code the Adsense code to your blog. These hacks are applied to your theme.</p>
<p>The obvious place to have your Adsense is on your home page. In this post, we&#8217;ll look at inserting Adsense on your hope page. This would be in the loop in the <code>index.php</code> page. As you can guess, it will also be applied to other pages that use the loop, namely the various archives pages.</p>
<p>Let&#8217;s begin:</p>
<p>Open the <code>index.php</code> file of your theme and find the line <code>&lt;?php if ( have_posts() ) : ?&gt;</code> and add the following just <strong>before</strong> this line:</p>
<p><code>&lt;?php<br />
&nbsp; &nbsp; $postnum = 1;<br />
&nbsp; &nbsp; $showadsense1 = <em>n1</em>;<br />
&nbsp; &nbsp; $showadsense2 = <em>n2</em>;<br />
&nbsp; &nbsp; $showadsense3 = <em>n3</em>;<br />
?&gt;</code></p>
<p>Just change <em>n1</em>, <em>n2</em>, and <em>n3</em> to whatever posts you want the Adsense to appear after. So if you want it to appear after the 1st, 4th and 8th posts, just change it to 1, 4 and 8 respectively. Also, if you only want one Adsense unit in the loop, discard the lines: <code>$showadsense2 = n2;</code> and <code>$showadsense3 = n3;</code>.</p>
<p><span id="more-113"></span>Next, scroll down to the line <code>&lt;?php endwhile; ?&gt;</code> and add the following code just <strong>before</strong> it:</p>
<p><code>&lt;?php if ($postnum == $showadsense1) {<br />
&nbsp; &nbsp; echo '<br />
&nbsp; &nbsp; &nbsp; &nbsp; Your adsense code<br />
&nbsp; &nbsp; ';<br />
} ?&gt;</p>
<p>&lt;?php if ($postnum == $showadsense2) {<br />
&nbsp; &nbsp; echo '<br />
&nbsp; &nbsp; &nbsp; &nbsp; Your adsense code<br />
&nbsp; &nbsp; ';<br />
} ?&gt;</p>
<p>&lt;?php if ($postnum == $showadsense3) {<br />
&nbsp; &nbsp; echo '<br />
&nbsp; &nbsp; &nbsp; &nbsp; Your adsense code<br />
&nbsp; &nbsp; ';<br />
} ?&gt;</p>
<p>&lt;?php $postnum++; ?&gt;</code></p>
<p>Obviously, you need to replace <code>Your adsense code</code> with your adsense code. If you only want one Adsense unit, discard the second and third bits of php code.</p>
<p>That&#8217;s it, just upload the altered <code>index.php</code> page to your theme folder and your Adsense will be enabled. </p>
<p>Maybe you don&#8217;t want Adsense to appear on archives pages that have only one post as that might look MFAish? Not a problem, just show Adsense from the second post onward. Alternatively, you can filter out archive pages that have a post count of 1 by using <code>$wp_query->post_count</code> in the first bit of php code that inserts your Adsense code. In other words, you&#8217;d replace the code that you inserted before the line <code>&lt;?php endwhile; ?&gt;</code> with the following:</p>
<p><code>&lt;?php if ($postnum == $showadsense1) {<br />
<strong>&nbsp; &nbsp; if (($wp_query->post_count) == 1) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo ' ' ; }<br />
&nbsp; &nbsp; else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo '<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Your adsense code<br />
&nbsp; &nbsp; &nbsp; &nbsp; ';<br />
&nbsp; &nbsp; }</strong><br />
} ?&gt;</p>
<p>&lt;?php if ($postnum == $showadsense2) {<br />
&nbsp; &nbsp; echo '<br />
&nbsp; &nbsp; &nbsp; &nbsp; Your adsense code<br />
&nbsp; &nbsp; ';<br />
} ?&gt;</p>
<p>&lg;?php if ($postnum == $showadsense3) {<br />
&nbsp; &nbsp; echo '<br />
&nbsp; &nbsp; &nbsp; &nbsp; Your adsense code<br />
&nbsp; &nbsp; ';<br />
} ?&gt;</p>
<p>&lt;?php $postnum++; ?&gt;</code></p>
<p>There&#8217;s no need to alter the second and third iterations of the Adsense code as these won&#8217;t appear anyway if there&#8217;s only one post.</p>
<p>In our next post we&#8217;ll look at creating a short code to insert Adsense in your posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.poiesis.co.za/index.php/2009/08/adding-adsense-code-to-your-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

