Using Conditional tags, you can specify under what conditions parts/widget/code/script of your template will appear or behave.
Let’s say, you want the “contact form” widget only to show on the “contact us” page that you have on your blogger site or, you want to add meta tags to a particular page, or you want a different style for your homepage or any other page. You cannot do them without using the conditional tags.
Knowing the conditional tags and using them is very important for every blogger user. The conditional tag syntax is made up of a
<b:if> tag with acondattribute added for entering the condition. For the closing the tag,
</b:if>, the closing tag is used. The syntax is like this;
<b:if cond='your condition'> YOUR CONTENT HERE </b:if>
inclosingBelow is a list of conditional tags that target specific pages. I only list the opening tags here. Just make in the closing tag
</b:if> when applying a conditional in your template.
1. Conditional tags for Homepage
Used for home page of the blog; anything inside it will load the home page of your site;
<b:if cond='data:blog.url == data:blog.homepageUrl'> EXECUTE IN HOMEPAGE ONLY </b:if>
In the case of static page redirects for your homepage, you’ll need to use the specific page URL code in the next section.
2. Post and Static Pages Conditional tags
For targeting both post and static pages in the blog.
<b:if cond='data:blog.url == data:post.url'> EXECUTE IN POST AND STATIC PAGES ONLY </b:if>
3. Static Page Conditional Tags
Blogger users often want static pages behavior somewhat different from other pages in the blog.
<b:if cond='data:blog.pageType == "static_page"'> EXECUTE IN ON STATIC PAGES ONLY </b:if>
4. Blog Post Page Conditional tag
This tag used for Blog posts pages.
<b:if cond='data:blog.pageType == "item"'> EXECUTE IN BLOG POST PAGES </b:if>
5. Conditional Tag for Index pages
Index pages are pages show by default multiple blog posts on one page i.e. homepage, labels page, QUERYand yearly archive page. Index
<b:if cond='data:blog.pageType == "index"'> EXECUTE IN INDEX PAGES </b:if>
6. Label or Search page
Pages that are log on by clicking on a label link from the label list or cloud or labels given after a blog post.
<b:if cond='data:blog.searchLabel'> EXECUTE IN LABEL OR SEARCH PAGES </b:if>
7. Conditional Tag for Pages with Search Query
Pages with the search query. For example //atestblogforyou.blogspot.comsearch?q=blogger&submit=Search.
<b:if cond='data:blog.searchQuery'> EXECUTE IN PAGES WITH SEARCH QUERY </b:if>
8. Conditional Tag for Archive page
The archive page is the one that people reach by click on a Year or Month value in your Archive widget.
<b:if cond='data:blog.pageType == "archive"'> EXECUTE IN ARCHIVE PAGES </b:if>
First post Conditional tag
Not for a page type; used for targeting the first post on multi-post pages (index, archive, label).
<b:if cond='data:post.isFirstPost'> EXECUTE ALONG WITH THE FIRST PAGE </b:if>
9. Conditional Tag for Error page
The error page is the “404” errors. By entering a link which is not available on you blog/site you can access it.
<b:if cond='data:blog.pageType == "error_page"'> EXECUTE IN 404 OR ERROR PAGE </b:if>
10. Conditional Tag for a Specific page/URL
It is used for applying conditions to a specific page/URL.
<b:if cond='data:blog.url == "URL"'> EXECUTE IN A SPECIFIC PAGE </b:if>
These are the conditional tags for blogger page types. Now see the ways how to use them in a blogger template.
Applying Conditional Tags in Blogger
For Appling conditional tag to a content;
<b:if cond='data:blog.pageType == "item"'> CONTENT (TO BE EXECUTED IF CONDITION IS TRUE) </b:if>
As you see; put the content between the opening
<b:if cond…> and the closing
</b:if>. In the example above, the content will only appear on post pages.
Reversing a Condition
You can easily reverse a condition by changing the comparison operator from
== (is equal to) to
!= (is not equal to);
<b:if cond='data:blog.url != data:post.url'> EXECUTE IF TRUE </b:if>
Execute Multiple Condition
If you want to specify an alternate content (when the condition is false), you need to insert a
<b:else/> tag followed by the content, like this:
<b:if cond='data:blog.pageType == "item"'> EXECUTE IF TRUE <b:else/> EXECUTE IF FALSE </b:if>
Except inside a section or inside a widget content box, you can place the conditional anywhere in your template HTML. The content can be a div, a section, a style tag, another conditional tag etc.
If you are using these page types within your HTML as opposed to the template language Blogger might throw an error due to escaping of your characters. What this means is that the quotation marks need to be “escaped” and replaced with ". So
<b:if cond='data:blog.pageType == "static_page"'> would be added as
<b:if cond='data:blog.pageType == quot;static_pagequot;'>
It’s important for every blogger user to know the use of conditional tags for blogger. It helps to make changes in your blog that would make it dynamic and awesome.