Often we want to display ads on selective posts. By default, once the ad code has been added to blogger template, it appears on every single blog post. Suppose, we do not want to show ads on About, Contact and Archive pages. Or we want that posts having more than 10 comments should get image banner ads instead of text ads. Suppose you have a multi author blog, and you want that every author runs its own ad code on the post written by them. Or you may want that posts with tag 'Software' display no ad or only display only image ad. How to do all this? Well, here is the solution.
------------------------------------------------------------------------------------------------------------------------------
Display Author's Own Ad Code On His Post
Suppose, there is a multi-author blogger blog owned by Alex, Peter and Melinda. They all have Adsense accounts and want to display their own ad code on the posts written by them. How to achieve this? Let's see...
The following code will run each author's own ad code on the post written by them. In this example, the ad will appear at the end of post body. If you want to display the ad just below the post title shift the if...else section above the <data:post.body/> line.
<data:post.body/> |
------------------------------------------------------------------------------------------------------------------------------
Run Custom Code On Selective Posts
Let's take one more example. Suppose, we decide not to show any ad on About, Contact and Archive pages. Or we may decide to run some custom code instead of Adsense ad on these pages. To achieve this, our template code must identify the correct page while reader is opening it in the browser. How to achieve this? Let's see...
Every post in blogger has a unique post ID associated with it. This post ID is generated when the post is published. Drafts do not have any post ID associated with them. First open your post in blogger editor, in our example, it's Contact page. Now see the URL in your browser's address bar. You will find the post ID at the end of the URL, as shown in the image below.
Copy this code in notepad and close the post. Now add the following code in your template.
Note: Replace xxxxxxxxxxxxxxxxxxx with your post ID |
<data:post.body/> |
------------------------------------------------------------------------------------------------------------------------------
Run Custom Code on the Basis of Comments
Here is one more possibility. Let's say, a blogger may want to run custom code on posts having no comments or having more than 5 comments. On the other hand, he may want that posts having comments between 1 to 5 display regular Adsense ads. How to achieve this? Let's see...
Possibilities and combination's can be infinite. I just took an example to explain the trick.
<data:post.body/> |
------------------------------------------------------------------------------------------------------------------------------
Run Add On Custom Code Based On Post Tags (Categories)
Here is one more example. Suppose, you want to run custom code on all those posts having 'Software' tag (Category) associated with them, in addtion to your regular Adsense code. How to achieve this? Let's see...
Note: Replace Software with your Tag (Category) |
<data:post.body/> |
NOTE: You can shift these codes to appropriate place in the template according to your needs.
0 comments:
Post a Comment