Conditional tags in Blogger are used to tell browsers what to do in certain conditions. For example, when we use:
<b:if cond='data:blog.pageType == "item"'>
Hello world
<b:else/>
Goodbye Cruel World
</b:if>
It gives the browser the condition that when it’s an item (post) page then show “Hello world” otherwise, for every other pages show “Goodbye Cruel World”. Interesting, isn’t it.
A conditional tag comes handy when you are designing your Blogger blogs and customizing it from the scratch to take it to the next level. But first you need to know how many types of pages are there in Blogger and then how to use the conditional tags respective to that type of page. In this tutorial I will try to cover most of it, so let’s start.
Type of Pages in Blogger and Conditional Tags For It
Item Page
Item page refers to the individual post pages. It’s the page when you click the tile of the post or the read more link in blogger to read the full post. The conditional tag:
<b:if cond='data:blog.pageType == "item"'>
Hello World
</b:if>
Index Page
It refers to every other page except item (post) pages. The conditional tag:
<b:if cond='data:blog.pageType == "index"'>
Hello World
</b:if>
Archive Page
It’s for your archive pages in Blogger. The tag will be:
<b:if cond='data:blog.pageType == "archive"'>
Hello World
</b:if>
Static Page
For static pages in blogger it will be:
<b:if cond='data:blog.pageType == "static_page"'>
Hello World
</b:if>
For a Particular Page
If you want to do something on a particular page then the conditional tag for it will be:
<b:if cond='data:blog.url == "URL of the page"'>
Hello World
</b:if>
The only thing that you have to do is replace “URL of the page” with your page’s URL which you want to have.
Homepage only
It's for the homepage only.
<b:if cond='data:blog.url == data:blog.homepageUrl'>
Hello World
</b:if>
Alternative Condition
Now suppose you want a conditional tag that alternates every rule. Say, in example 1, I showed how to display something only in post pages but just an “!” mark can alternate the condition. For example, when we apply:
<b:if cond='data:blog.pageType != "item"'>
Hello World
</b:if>
It will set the condition that to show it on every page other than post page.
Conclusion
“Hello world” is an example, but if it’s implemented correctly, you can add conditions to particular widgets or gadgets to show them in specific pages. However, you can find in most of my tutorials that I have used it. Have a look at my getting social tutorials for blogger, you will find the tags.