How to Use Blogger Blogspot Conditional Tags 2018

January 13, 2018 July 20, 2018

To use Tag condition, you should have a little knowledge about HTML. The condition starts with “ cond “ finish with close tag. Between these tags, content (html ,style, script, widgets…) just appear or comply with certain conditions.
Example:
<b:if cond='your condition'>
 <style>...css code...</style>
 <script>...javascript code...</script>
</b:if> 

Part 1. Condition Tags

1. Homepage

<b:if cond='data:view.isHomepage'>
  <!-- The conditional Element To Execute -->
</b:if> 
Old version:
<b:if cond='data:blog.url == data:blog.homepageUrl'>
  <!-- The conditional Element To Execute -->
</b:if> 

2. Item Pages

<b:if cond='data:view.isPost'> 
 <!-- The conditional Element To Execute -->
</b:if> 
Old version:
<b:if cond='data:blog.pageType == "item"'> 
 <!-- The conditional Element To Execute -->
</b:if> 
For a specific article page:
<b:if cond='data:blog.url == data:blog.canonicalHomepageUrl + "2018/01/postn.html"'>
  <!-- Add content for post your-domain/2018/01/postn.html-->
</b:if> 

3. Static page

<b:if cond='data:view.isPage'>
 <!-- The conditional Element To Execute -->
</b:if> 
Old version:
<b:if cond='data:blog.pageType == "static_page"'>
 <!-- The conditional Element To Execute -->
</b:if> 

4. Index pages (home, archive, label and search pages)

<b:if cond='data:view.isMultipleItems'>
  <!-- The conditional Element To Execute -->
</b:if> 
Old version:
<b:if cond='data:blog.pageType == "index"'>
  <!-- The conditional Element To Execute -->
</b:if> 

5. Label search Page

<b:if cond='data:view.isLabelSearch'>
  <!-- The conditional Element To Execute -->
</b:if>
.................
<b:if cond='data:view.isLabelSearch == "blogger"'>  
<!-- The conditional Element To Execute if label is "blogger"-->
</b:if> 
Old version:
<b:if cond='data:blog.searchLabel'>
  <!-- The conditional Element To Execute -->
</b:if>
.................
<b:if cond='data:blog.searchLabel == "blogger"'>  
<!-- The conditional Element To Execute if label is "blogger"-->
</b:if> 

6. Search Result Page (ex: /search?q=blogger)

<!-- Include Label Search Page -->
<b:if cond='data:view.isSearch'> … </b:if>

<!-- Just search result page -->
<b:if cond='data:view.isSearch and !data:view.isLabelSearch'> … </b:if>
Old version:
<b:if cond='data:blog.searchQuery'> 
   <!-- The conditional Element To Execute --></b:if>

...................................

<b:if cond='data:blog.searchQuery == "blogger"'>
  <!-- The conditional Element To Execute in key search is "blogger"-->
</b:if> 

7. 404 Error Page

<b:if cond='data:view.isError'>
  <!-- The conditional Element To Execute -->
</b:if> 
Old version:
<b:if cond='data:blog.pageType == "error_page"'>
  <!-- The conditional Element To Execute -->
</b:if> 

8. Archive Page

<b:if cond='data:view.isArchive'> 
 <!-- The conditional Element To Execute -->
</b:if> 
Old version:
<b:if cond='data:blog.pageType == "archive"'> 
 <!-- The conditional Element To Execute -->
</b:if> 

9. Mobile Device

<b:if cond="data:blog.isMobile">
<!-- The conditional Element To Execute -->
</b:if> 

10. For multi posts per page, apply for first post

<b:if cond='data:post.isFirstPost'>
 <!-- The conditional Element To Execute -->
</b:if> 

11. Static Page and Item

<b:if cond='data:view.isSingleItem'>
<!-- The conditional Element To Execute -->
</b:if> 
Old version:
<b:if cond='data:blog.url == data:post.url'>
<!-- The conditional Element To Execute -->
</b:if> 

12. Condition for Thumbnail

<b:if cond='data:post.thumbnailUrl'>
  <!-- The conditional Element To Execute -->
</b:if> 

13. Condition for Author

<b:if cond='data:displayname == "author-name"'> 
<!-- The conditional Element To Execute -->
</b:if> 

14. Condition for total of comments

<b:if cond='data:post.numComments == number'>
 <!-- The conditional Element To Execute -->
</b:if> 

15. Preview Page

<b:if cond='data:view.isPreview'> 
… 
</b:if>

16. Condition for last Label

<b:loop values='data:post.labels' var='label'>
    <b:if cond='data:label.isLast != &quot;true&quot;'>
 <!-- Add special character after If it is not last label -->
       ,
    </b:if>   
</b:loop> 

Part 2. Applying Conditional Tags

1. Comparing operators

There are conditions that using double equals (comparing method), and just direct statement. The double equals == means TRUE for non-numeric statement, and equal to for an integer (numeric). Numeral The == operator can be replaced by:
  • != other than that integer.
  • < less than.
  • > greater than.
  • <= less than or equal to.
  • >= greater than or equal to.
Note: We need to escape the less than (<) and the greater than (>) marks. less than (<) is &lt; greater than (>) is &gt;
Example for escaping greater than operator
From this:
<b:if cond='data:post.numComments > 1'>...content...</b:if>
in to this:
<b:if cond='data:post.numComments &gt; 1'>...content...</b:if>
* Reverse Conditional Tags
We have two options for the operator:
== TRUE
!= FALSE

2. Applying Multiple Conditional Tags

By putting <b:else> tag, you can add multiple condition. It means that if first condition not work then execute second condition to all of pages. See example below 
<b:if cond='data:blog.pageType == "item"'> 
           Content-1 EXECUTE IF TRUE 
<b:else/>
           Content-2 EXECUTE IF FALSE 
</b:if> 
Above example means that execute content-1 in post page. If it's not post page then execute content-2.

3. Using IN, OR, AND, NOT Logic Operators

<b:if cond='data:blog.pageType in {"static_page","item"}'>
CONTENT
</b:if> 
<b:if cond='data:blog.pageType not in {"static_page","item"}'>
CONTENT
</b:if> 
<b:if cond='data:view.isPage and data:view.isPost'>
CONTENT
</b:if> 
<b:if cond='data:view.isPage or data:view.isPost'>
CONTENT
</b:if> 

Part 3. More 

When you edit your theme, maybe will be replace by quot;. Example
from this
<b:if cond='data:blog.pageType == "static_page"'> 
into this
<b:if cond='data:blog.pageType == quot;static_pagequot;'> 

Note: Using condition in tag b:include totaly similiar tag b:if

2 comments for How to Use Blogger Blogspot Conditional Tags 2018