Conditional Tags - Targeting Specific pages In Blogger
W3C validate blogger XHTML template~Must Read | | | Complete SEO Guide Step by Step | | | My Huge Dofollow Blogs List
Google Groups

Subscribe to our Newsletter to GET SEO Tools, Backlink Resources, SEO E-books , Make Money Online and Make Money Blogging Guides delivered to your mail box Absolutely FREE!!!

Hot!!! Get Complete Email Marketing Course "How to start from Scratch and earn like a pro". Guide will be delevered to your mailbox within 24 hours of your subscription

Email:
ProSEOexpert

Nov 2, 2011

Pin It

Conditional Tags - Targeting Specific pages In Blogger

You may ever need to display any blogger widget or adsense ads unit in one (or more) specific page(pages) such as home page,item or post page,index or list page,label page,yearly archive page,static page,or a specific page using its url this can be done using conditional tags in blogger. 

Today i am going to explain you the different conditional tags along with their implementation in your blogger template to show specific widget or adsense adds on the specific pages according to your need.



General syntax of conditional tag is as follows:
<b:if cond='YOUR CONDITION HERE'>
Your task to perform
</b:if>
In above syntax you can use different conditions (I am going to explain each bellow) if your condition is found true then only the task written in the code will be performed and if your condition is found false then task will be skipped.
Now lets discuss some conditions that we need to use frequently. 
  • How to display any blogger widget or adsense ads unit only in homepage

Now for performing this task we need to setup a conditional tag as follows,
<b:if cond='data:blog.url == data:blog.homepageUrl'>
 Your widget code or your adsense ads code here
</b:if>
Now what is the meaning of above code?

In above code we used condition 
cond='data:blog.url ==data:blog.homepageUrl' 

The meaning of this condition is that the task to be performed that is the text written above in red colour ,will be only performed if the current page is a homepage i.e. your blogger widget or adsense ad unit will only displayed on homepage.

There are two possiblities about using this code as follows,

1)When you want to add any blogger widget code directly in template then you just have to change your code like this, 
<b:if cond='data:blog.url == data:blog.homepageUrl'>
Your original widget code or your adsense ads code here 
</b:if>
And you are done.

2) Suppose you have a widget in your sidebar and you have to display it only on the homepage, Now firstly you need to find the location of the code in your template, How will you find?

Here I tell you a simple trick to find any widget code location in blogger template and apply conditional tags.

This is my facebook like box situated in my sidebar.


Now we will find its code location in my blogger template and then we will apply conditonal tag to it to show it only in homepage.

Steps: 

· Go to blogger dashboard click on design and add a title to the widget. I have given it title Ritesh009.



· Now click on edit html and then check the box expand widget templates.

· Now search Ritesh009 ( press ctrl+f to search) ,this will give you the location of the code of the widget now you can add conditional tag to this code as shown bellow,



And done, now the facebook like box widget will be shown only on the homepage.

This was only a example you can use this technique to design your blogger template like a problogger.

Different conditional tags are as follows, 
  • For item pages i.e post pages: 

<b:if cond='data:blog.pageType == "item"'>

  • For index i.e. list pages: 
Index pages includes homepage,labels page ,and your yearly archieve page. 
<b:if cond='data:blog.pageType == "index"'>

  •   For Archive page: 
<b:if cond='data:blog.pageType == "archive"'> 

  • For static page: 

<b:if cond='data:blog.pageType == "static_page"'>
  • For homepage 

<b:if cond='data:blog.url == data:blog.homepageUrl'>
  • For specific page(using its url as condition) 

<b:if cond='data:blog.url == "Put url of page here"'>

Some extra knowledge about conditional tags for probloggers:
  •  Adding alternative false condition using <b:else/> tag:
<b:if cond='YOUR CONDITION HERE'>
Task 1(will be executed if condition is true)
<b:else/>
Task 2(Will be executed if condition is false)
</b:if>
  • Reversing a condition using != operator:
<b:if cond='data:blog.url != data:blog.homepageUrl'>
Your widget code or your adsense ads code here
</b:if>
Now as we used != i.e not operator in above conditional tag, the conditon is reversed i.e now the widget will be displayed in all the pages except homepage.
Happy blogging :)

12 comments :

Anonymous said...

Great tips! I've been trying to figure out how to do this for a while now. This is information many seo companies don't post on their websites, but which is super useful for every seo rookie out there. Thanks a lot for posting this! Looking forward to more useful info from you!

Ritesh Warke said...

@torkeleckman,
Subscribe us to stay tuned :)

SLRC CALABARZON said...

just want to know how to apply same condition for another page. thanks

SLRC CALABARZON said...

or how to combine 2 more URL for the condition selected. thanks

Ritesh Warke said...

This comment has been removed by the author.

Ritesh Warke said...

@REUS,

simply use conditional tag twice as,


<*b:if cond='data:blog.url == "Put url 1 here"'>
<*b:if cond='data:blog.url == "Put url 2 here"'>

YOur widget code, Say its a about author widget.

<*/b:if>
<*/b:if>

Now that about author widget will be only visible if url of page is either of two.

(Remove stars*)

Narinder Singh said...

Hi. Thanx for the info. Is it possible to have a blogger conditional tag for:

Display a Bangkok hotel ad if the label or the post title contains the word "Bangkok"?

Will really appreciate!

Ritesh Warke said...

^
Do this,


<*b:loop values='data:post.labels' var='label'>
<*b:if cond='data:label.name == "Bangkok"'>

YOur widget code

<*/b:if>
<*/b:loop>

Note: You will need to be inside Blog Posts loop in order to use this code.

(Remove stars*)

Narinder Singh said...

Hi. Thanx but I do not have any label named "Bangkok". My labels are like "Bangkok_Hotel" or "Bangkok_Indian_Food". In all the Bangkok related pages, I want the same ad to appear. I can write separate loops for each label but the code becomes very long. In all there are 30 labels. So I will have to write 30 code sets. I was wondering if there is a condition like "label contains the word 'Bangkok', do this. Please see if you can find a way.

Regards.

Ritesh Warke said...

^No, its not possible.
But you can do one thing.
Add a dummy laabel to each post having bankok in its label. Then you can use this dummy label as condition.

Narinder Singh said...

Yeah that is possible. Only the dummy label will show along with the regular label below every post. Thanx a lot for your help.

Muhammad Shoaib said...

how can i learn blogger xml complete. is any website you know please share with me

Post a Comment

1. Feel free to share your opinion with us.
2. Spam = Trash
3. Use your real name and we don't mind giving you backlink.

Regards
Ritesh Warke