How to Use Conditional Tags for Blogger Page Types

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 add meta tags for a particular page, or you want a different style for your home page 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 a cond attribute added for entering the condition. For closing </b:if> tag is used. The syntax is like this;

<b:if cond='your condition'>
YOUR CONTENT HERE
</b:if>Conditional Tags for Blogger Page Types blogger conditional tags How to Use Conditional Tags for Blogger Page Types Blogger pages type conditional tags

Below is a list of conditional tags that target specific pages. I only list the opening tags here. Just make sure you include the closing </b:if> tag when applying a conditional in your template.

1. Conditional tags for Blogger Home page

Used for home page of the blog; anything inside this will load in the home page of your site;

<b:if cond='data:blog.url == data:blog.homepageUrl'>
EXECUTE IN HOMEPAGE ONLY
</b:if>

2. Blogger Post Page and Static Pages Conditional tags

For targeting both post and static pages in blog.

<b:if cond='data:blog.url == data:post.url'>
EXECUTE IN POST AND STATIC PAGES ONLY
</b:if>

3. Blogger Static Page Conditional Tags

Blogger users often want static pages’ behavior and style somewhat different from other pages in blog.

<b:if cond='data:blog.pageType == "static_page"'>
EXECUTE IN ON STATIC PAGES ONLY
</b:if>

4. Blogger 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. Blogger Conditional Tag for Index pages

Index pages are the pages the show by default the multiple-blog posts as a summary or collection on one page i.e. Homepage, labels page, search query and yearly archive page.

<b:if cond='data:blog.pageType == "index"'>
EXECUTE IN INDEX PAGES
</b:if>

6. Blogger Conditional Tag Label or Search page

Pages that are log on by clicking on a label link from the label list/cloud or labels given after a blog post.

<b:if cond='data:blog.searchLabel'>
EXECUTE IN LABEL OR SEARCH PAGES
</b:if>

7. Blogger Conditional Tag for Pages with Search Query pages

Pages with search query. For example: http://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 Blogger 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>

9. Blogger 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>

To avoid error you may require to use this inside the index page conditional tag.

10. Conditional Tag for Error page

Error page are the “404” errors. By entering a link which is not available in you blog/site you can access it.

<b:if cond='data:blog.pageType == "error_page"'>
EXECUTE IN 404 OR ERROR PAGE
</b:if>

11. Conditional Tag for a Specific URL

It is used for applying conditions to a specific page/URL. This tag is required if you are using ‘redirects’ in your blog.

<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 Blog

For applying 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.

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 &quot. So <b:if cond='data:blog.pageType == "static_page"'> would be added as <b:if cond='data:blog.pageType == quot;static_pagequot;'>.

Reversing a Condition in Blogger

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>

Executing Multiple Conditions in Blogger

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.

Where will the Blogger Page Type Conditional Tags will not Work

You can these conditional tags almost anywhere in the template. However these are the exceptions

    1. You will not be able to use the conditional tags inside a <b:section> tag.
    2. Conditional tags will not work before a <b:widget> tag.
    3. If you fail to use the conditional tags logically. For example;
<b:if cond='data:blog.pageType == "item"'>
EXECUTE IN BLOG POST PAGES
<b:if cond='data:post.isFirstPost'>
EXECUTE ALONG WITH THE FIRST PAGE
</b:if>
</b:if>

The above code indicates that, target the first post in the post page; which is illogical as <b:if cond='data:post.isFirstPost'> as there is only on post in the item page.

Example of Using of Conditional Tags

In this website you will find the extensive use of the conditional tags in many post for Blogger blogs tips. Here are tips for blogger which are not possible without conditional tags.

  1. SEO work like, making Blogger blog titles SEO friendly.
  2. Adding markups like; Facebook open graph protocol, twitter cards,
  3. Adding customized widget and items like; customized Contact Form widget.
  4. Adding AdSense units in important places like, before or inside of post footer, below the post title.
  5. And more.

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, awesome and functional.

Hope information about conditional tags of blog helped you. If you are facing any issues in implementing them in you blog then do state them in the comments section, I will try my best to help.

Tags: blogblogger

Tech News

Tech Info Know

Comments are closed.