Poiesis Web Development » $wp_query->post_count

Posts Tagged ‘$wp_query->post_count’

WordPressThere 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.

The obvious place to have your Adsense is on your home page. In this post, we’ll look at inserting Adsense on your hope page. This would be in the loop in the index.php page. As you can guess, it will also be applied to other pages that use the loop, namely the various archives pages.

Let’s begin:

Open the index.php file of your theme and find the line <?php if ( have_posts() ) : ?> and add the following just before this line:

<?php
    $postnum = 1;
    $showadsense1 = n1;
    $showadsense2 = n2;
    $showadsense3 = n3;
?>

Just change n1, n2, and n3 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: $showadsense2 = n2; and $showadsense3 = n3;.

Continue reading “Adding Adsense code to your blog” »

Tags: , , , ,