07
May
2008



Bookmark and Share

If you are a blogger you know only too well how important to put advertising on your bog is in order to pay your monthly and yearly fees to manage your internet activity. In fact, you have to pay the web hosting provider, ask for help to programmers just in case something gets screwed, pay a designer to get a better theme, pay Adword to let other people know about you and what you are doing etc. If you start blogging seriously and you are not into programming, at a certain point you have to pay to get help. Blogging is a continue work in progress. Usually readers don’t see a lot about this feverish activity, apart when a new article comes out, but I assure that behind the scenes there is a lot of work and posting articles is just the tip of the iceberg. Blogging is an extreme dynamic activity made of hundreds of big and small daily adjustments. OK, I apologize for this little off-topic… There are a lot of ways to get money from your blog, but the most used one is, without any doubt, Google Adsense. There are dozens of plugins letting you put its code among your pages or promising you to fine tune it, but what if you don’t manage to find the right plugin reproducing the behaviour you are looking for? A solution is to know a little bit about php programming, make a custom piece of code and put it into your blog’s theme. Let’s make an example. In the past weeks I have have been looking for a plugin which let me put and display Adsense in the loop on the main page of my blog ( by the way, I use WordPress) at specific intervals, let’s say one advertising every 3 posts. Well, believe it or not but I didn’t manage to find it at all. Lucky for me and you all, there are a lot of good guys out there willing to help you for the sake of it. This is the trick I managed to get from a good willed guy:

  • Get access to your blog thorugh your FTP software.
  • Go to /public_html/wp-content/themes/yourTheme.
  • Open Index.php (which corresponds to your blog’s homepage loop).
  • Add this piece of code right above <?php if (have_posts()) : ?>: <?php $counter = 2; ?>
  • Add this other piece of code containing your Adsense right before <?php endwhile; ?>: <?php if(++$counter % 3 == 0) { Echo ‘Your Google Adsense code here’; } ?>

The behaviour you should expect from this code is that it will put a Google ads at the bottom of the first post of your blog’s homepage. It will also put a Google ads every three posts, following thus this frequency: 3,6,9,12 etc. If you want your Google ads to follow a different frequency, just change the figures in the code.




Related Articles Latest Articles
.

One Comment to “How to put Google Adsense in the loop of your blog’s homepage”

  1. DSLR-A850 Says:

    Hal ini sangat true.I kehilangan berat badan saya hanya membuat perubahan dalam makanan, mengambil semua vegetarian dan rendah karbohidrat ini banyak membantu saya dan saya sarankan semua orang


Copyright © 2007-2017 | Sitemap | Privacy | Back To Top
Best screen resolution 1280x800 or higher.
Web Talk is best viewed in Firefox.

Stat