Showing posts with label Wordpress. Show all posts
Showing posts with label Wordpress. Show all posts

Wednesday, December 2, 2009

Show AdSense Ads After First or Every Post in Wordpress Blogs

Long time back, I wrote about showing Google AdSense ads after each post in blogger.com blogs. Now I am doing exactly opposite by limiting ads to only first post on home, archives, categories pages. Johnson wants to know how I am doing it!
To do this, You need to edit famous wordpress loop. Such a loop can be found in your current wordpress theme’s index.php. There may be other files present in your theme directory which uses loop like archives.php. They may need to be updated as well.
Listed below are steps to edit loop in index.php file. Similar steps can be performed for other files too, if required.
1. Go to Wordpress Dashboard >>Design >> Theme Editor.
2. Click on index.php or Main Index Template file. It will open in Theme Editor on left.
3. Find a line:
<?php while (have_posts()) : the_post(); ?>
4. Add before it:
<?php $adcount = 1; ?>
5. So final code will look:

<?php $adcount = 1; ?>
<?php while (have_posts()) : the_post(); ?>
6. Now find:
<?php endwhile; ?>
7. Add before it:
<?php $adcount++; ?>
8. So final code will look:
<?php $adcount++; ?>
<?php endwhile; ?>
9. Now inside loop, i.e. after “while” line but before “endwhile” line put your AdSense codes. Exact location depend on your choice between ads before post, ads after post, etc. Important thing is you have to put your AdSense code in a if-block. below is an example…

<?php if ($adcount == 1) : ?>
<!-- Put Your AdSense Code here -->
<?php endif; $adcount++; ?>
That’s it. Save changes and check if it works.

Variations…
1. If you want to put ads after first two post…
In step 9 code, Change $adcount == 1 to $adcount == 2
2. If you want to put ads after first three post…
In step 9 code, Change $adcount == 1 to $adcount == 3
3. If you want to put ads after each post…
In step 9 code, Change $adcount == 1 to $adcount == 3. Yes this is same like above. Because AdSense only
allows maximum three ad-units on a a single page. This way you avoid blank space created after each post
when you directly put AdSense code after each post.

If you need any help, or stuck at some point, feel free to contact via comment.

Customizing the Read More

If you have set your WordPress site to display post excerpts on the front or home page, you will want visitors to click on the title or a link to encourage them to continue reading your post or article, right? WordPress makes this technique easy, and customizable.

Excerpts show up on WordPress through two methods. One, by replacing the template tag the_content() with the_excerpt(). Then the explicit excerpt you have entered in the Administration > Write > Post SubPanel will appear, or the first 55 words of the post's content. Users can then click on the title to continue reading more as you have enticed them with your summary introduction. The most commonly used method is to keep the_content() template tag and insert a quicktag called more into your post at your desired "cut-off" point.

The quicktags are the little buttons found above the editing window in your Administration > Write > Post SubPanel. They include bold, italic, links, and others, and the famous more. Put your cursor where you want to end the excerpted content of your post and click the more quicktag button. It will insert a code at that point that looks like this:

Banner Ads

 

Site Info

Followers

Blog Resources Copyright © 2009 Blogger Template Designed by Bie Blogger Template