Conditional Tags for BlogSpot
If you want to specify a part of your code to work on specific types of pages or specific URLs, then you should use conditional tags. You can
- apply a meta tag to certain page,
- display a widget on specific pages,
- hide sidebar on some pages,
- or something else.
a Live Example from this website
<b:if cond='data:blog.pageType == "index"'>
<title><data:blog.pageTitle/></title>
<meta content='Keyword 1. Key word 2, a long Keyword 3' name='keywords'/>
<b:else/>
<b:if cond='data:blog.pageType != "error_page"'>
<title><data:blog.pageName/> | <data:blog.title/></title>
<b:else/>
<title>Sorry! You are in wrong page</title>
</b:if>
</b:if>
Now you should carefully check of the title of this webpage and the homepage of this www.devilhunter.net website to know how it works.
full list of Conditional Tags for BlogSpot ...
Homepage
<b:if cond='data:blog.url == data:blog.homepageUrl'>
<!-- only homepage -->
</b:if>
Index Page
<b:if cond='data:blog.pageType == "index"'>
<!-- all index pages -->
</b:if>
Item (post) pages
<b:if cond='data:blog.pageType == "item"'>
<!-- all item pages -->
</b:if>
Static page
<b:if cond='data:blog.pageType == "static_page"'>
<!-- all static pages -->
</b:if>
Specific Static page by URL
<b:if cond='data:blog.url == data:blog.canonicalHomepageUrl + "p/abc.html"'>
<!-- a specific static page with name 'abc' -->
</b:if>
Archive page
<b:if cond='data:blog.pageType == "archive"'>
<!--archive_Page-->
</b:if>
Error Page (404)
<b:if cond='data:blog.pageType == "error_page"'>
<!-- all error pages-->
</b:if>
Label page
<b:if cond='data:blog.searchLabel'>
<!-- all label pages -->
</b:if>
Specific Label Page
<b:if cond='data:blog.searchLabel == "abc"'>
<!-- for label 'abc' -->
</b:if>
Search page
<b:if cond='data:blog.searchQuery'>
<!-- all search pages -->
</b:if>
Specific Search Query page
<b:if cond='data:blog.searchQuery == "abc"'>
<!-- for query 'abc' -->
</b:if>
Specific Post by URL
<b:if cond='data:blog.url == data:blog.canonicalHomepageUrl + "2012/09/abc.html"'>
<!-- a item page from september 2012 with post-title 'abc'-->
</b:if>
AND
<b:if cond='data:blog.pageType == "index"'>
<b:if cond='data:blog.searchQuery'>
<!--search_page AND index_page-->
</b:if>
</b:if>
OR
<b:if cond='data:blog.url == data:blog.canonicalHomepageUrl + "p/abc.html"'>
<!-- static_site abc OR static_site xyz -->
<b:else/>
<b:if cond='data:blog.url == data:blog.canonicalHomepageUrl + "p/xyz.htm"'>
<!-- static_site abc OR static_site xyz -->
</b:if>
</b:if>
NOT
<b:if cond='data:blog.pageType != "item"'>
<!-- all pages except item pages -->
</b:if>
<b:if cond='data:blog.url != data:blog.homepageUrl'>
<!-- all pages but NOT homepage -->
</b:if>
How conditional tags work?
Type the code or content inside the opening <b:if cond…> and the closing </b:if> like:
<b:if cond='data:blog.pageType == "item"'>
CODE
</b:if>
In the example above, the code/content will only work on post pages. The content can be a
- meta tag,
- div,
- a section,
- a style tag
- or another conditional tag etc.
If you want to specify a alternate code (if the condition is false), you need to insert a <b:else/> tag followed by the content, like this:
<b:if cond='data:blog.pageType == "static_page"'>
# If the condition is true, this code will work
# i.e. if current page is static page
<b:else/>
# If the condition is false, this alternative code will work
# i.e. if not static page
</b:if>
Here <b:else/> also works like an OR operator also.