Blogger templates are designed using XML. XML has an excellent and powerful feature called the conditional tags. Alot of bloggers don’t know about this, but it’s an added advantage if you can understand the principle behind it. I will quickly walk you through the conditional tags of blogger.
Have you ever wished that a particular blogger gadget shows only on your homepage and not in posts pages? Perhaps the reverse would have also come to mind. With the conditional tags, you can make all that happen almost effortlessly.
Exploring Blogger Conditional Tags:
- cond -This refers to the condition
- Your Condition – The user’s condition is placed here
- Your code or text – The code or text which will will be displayed according to the condition.
- – This defines the end of a blogger conditional tag.
1. Homepage
[code type=html]
<b:if cond=’data:blog.url == data:blog.homepageUrl’>
Text or code that will be displayed only on Homepage.
</b:if>[/code]
2.Index
[code type=html]
<b:if cond=’data:blog.pageType == “index”‘>
Text or code that will be displayed on homepage, labels page and archive page.
</b:if>[/code]
3. Static Page
[code type=html]
<b:if cond=’data:blog.pageType == “static_page”‘>
Text or code that will be displayed on static pages.
</b:if>[/code]
4. Post Page
[code type=html]
<b:if cond=’data:blog.pageType == “item”‘>
Text or code that will be displayed only on post pages only
</b:if>[/code]
5. Specific Page/Url
[code type=html]
<b:if cond=’data:blog.url == “PUT_URL_HERE”‘>
Text or code that will be displayed only on specific url
</b:if>[/code]
6. Post and Static Pages
[code type=html]
<b:if cond=’data:blog.url == data:post.url’>
Text or code that will be displayed only on posts and static pages
</b:if>[/code]
7. Specific Label Tags
[code type=html]
<b:if cond=’data:blog.searchLabel’>
Text or code that will be displayed only on the specific tag page
</b:if> [/code]
8. Archive Page Tags
[code type=html]
<b:if cond=’data:blog.pageType == “archive”‘>
Text or code that will be displayed only on archive pages only
</b:if>[/code]
9. First Post
[code type=html]
<b:if cond=’data:post.isFirstPost’>
Text or code that will be displayed only after the first post title of a multi-post blog
</b:if>[/code]
Using The <b:else/> Tag in Blogger
Blogger allows you to place an alternate content when the condition is false. To do so you need to insert <b:else/> tag after the closing conditional tag;
For Example;
[code type=html]<b:if cond=’data:blog.pageType == “item”‘>
Content 1 (To be executed if condition is true)
<b:else/>
Content 2 (To be executed if condition is false)
</b:if>[/code]
Hint: You can place the conditional tag anywhere in your blogger template except inside a widget content box or a section.
Hot:
7 Comments
Results 2013
Nice Post sir,
I was looking for the Blogger Conditional Tags and got it. Thank you.
w0ng
Nice post.. i”ll try it 🙂
Diwali SMS
Thanks to share this
kaushalkpr
excellent article Nosa. Quite helpful
Nosa E Nosa
Thanks buddy 🙂
kaushalkpr
Hey, i have encountered a problem while editing my template. I have explained my problem in stackoverflow:
http://goo.gl/SO95gd
Please take a look and help me if you can
Ali
Is there a way to make content appear on every page? At the moment I have some social media buttons following my post content, but they only appear on the homepage. I’d like them to appear on every page (static pages, individual posts etc). I’ve tried playing with b:if and b:else tags but I don’t seem to be doing it right. I’m not using any of those tags at the moment and the buttons are still only appearing on the homepage.
Do you have any advice? Thanks!