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>
- 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>
In above code we used condition
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>
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:
<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>
12 comments :
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!
@torkeleckman,
Subscribe us to stay tuned :)
just want to know how to apply same condition for another page. thanks
or how to combine 2 more URL for the condition selected. thanks
This comment has been removed by the author.
@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*)
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!
^
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*)
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.
^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.
Yeah that is possible. Only the dummy label will show along with the regular label below every post. Thanx a lot for your help.
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