Close

×

Tutorials

Blogger Tutorial

Start Blogger

Templates

Blogger Templates

Recent Post Popular Post Featured Post Related Post

nayan ad

Share


Like
×

Top Navigation Menu

×

Search v5Blogger

Powered by Google

Blogger <b:if> Tag

The b:if tag lets you display content logicaly.
  • Display certain content in particular cases & other content in other cases.
  • Creating a logical condition for activate a section of code.
  • The logical tags are b:ifb:else and b:elseif
  • For example, you might only want to show certain text on the homepage, but different text when looking at individual posts.

HTML b:if Syntax

Each Blogger b:if in your template has opening and closing tags.

<b:if cond='condition'>
  Display if condition is true
<b:elseif cond='another condition'/>
  Display if condition is false and elseif condition is true
<b:else/>
  Display if no if or elseif conditions are met
</b:if>
The b:elseif and b:else tags are optional. Without them, the result will be either the content listed in the b:if section or nothing. The closing </b:if> is required in each case.

Usage of b:if Tag

Go to Template > Edit HTML.

Blogger Section: new

<html>
<head>
<title><data:blog.pageTitle/></title>
<b:skin/>
</head>

<body>
<b:if cond='data:blog.pageType == "item"'>
  I am Post
<b:else/>
  I am not a Post
</b:if>

<b:section id='new'>
  <b:widget id='Blog1' type='Blog'/>
</b:section>

</body>
</html>

Post

If current page is a post page it show "I am a Post". Otherwise it show "I am not a Post".

HTML b:if Conditions

For "condition" you can put in anything that evaluates to either true or false. Some data tags are simply true/false values on their own, e.g. allowComments on a post. With other pieces of data, you can compare them with specific values to get a true or false.

Code Description
<b:if cond='data:post.showBacklinks'> True if the current post is set to show backlinks.
<b:if cond='data:blog.pageType == "item"'> True if the current page is an item page (post page).
<b:if cond='data:post.numComments > 1'> True if the current post has more than one comment.
<b:if cond='data:blog.pageType == "item" and data:post.showBacklinks'> True if the current page is an item page (post page) and the current post is set to show backlinks.
<b:if cond='data:displayname != "Fred"'> True if this is not Fred's display name.
<b:if cond='data:blog.pageType in {"static_page", "item"}'> OR <b:if cond='{"static_page", "item"} contains data:blog.pageType'> True if the current page is a specific post, or a page.
<b:if cond='data:displayname == "Fred" or data:blog.pageType == "static_page"'> True if Fred is the display name, or the current page is a static page (not a post page).

Footer Note

v5 Blogger is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2016. All Rights Reserved.
Powered by W3.CSS.

v5 Library