All about Blogger conditional tags

Sunday, 27 January 20130 comments


What are conditional tags?

Conditional tags allow you to specify parts of your template to appear only under certain conditions. It is very similar to conditional tags in any other language. This includes tags such as ifif else. These conditional statements could be used on widgets, or actual html codes you may want to display on certain pages. If Else type conditional programing in blogger can be done by using <b:if cond=' '>...</b:if> tag. In this post we have examples of the use of conditional tags on html or widgets. 


Table of contents

  • Home Page Only
  • Archive Page Only
  • Item Page or Post Page Only
  • Static Page Only
  • Specific URL Page Only
  • Certain Labels Only

Home Page Only

To display a text message only on home page we use 
<b:if cond='data:blog.url == data:blog.homepageUrl'> 
<p> This text will be displayed only on home page</p>
</b:if>

And to display it everywhere except homepage we use
<b:if cond='data:blog.url != data:blog.homepageUrl'> 
<p>This text will be displayed everywhere except on home page</p>
</b:if>

If you want to display a widget only on home page, you will use the conditional code as highlighted on the following code for a blogger html/Javascript widget
<b:widget id='HTML1' locked='false' title='Testing Widget' type='HTML'>
<b:includable id='main'>
<b:if cond='data:blog.url == data:blog.homepageUrl'> 
<!-- only display title if it's non-empty -->
<b:if cond='data:title != &quot;&quot;'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>
</b:if>
<b:include name='quickedit'/>
</b:includable>
</b:widget>

Archive Page Only

To display html code only on archive page
<b:if cond='data:blog.pageType == &quot;archive&quot;'> 
<p>Text for Archive pages only</p>
</b:if>

To display html code everywhere except archive page
<b:if cond='data:blog.pageType != &quot;archive&quot;'> 
<p>Text for everywhere except Archive pages</p>
</b:if>

Item/Post Page Only

To display html code only on item page
<b:if cond='data:blog.pageType == &quot;item&quot;'> 
<p>Text for post pages only</p>
</b:if>

To display html code everywhere except item page
<b:if cond='data:blog.pageType != &quot;item&quot;'> 
<p>Text for everywhere except item pages</p>
</b:if>

Static Page Only

To display html code only on static pages
<b:if cond='data:blog.pageType == &quot;static_page&quot;'> 
<p>Text for static pages only</p>
</b:if>

To display html code everywhere except static page
<b:if cond='data:blog.pageType != &quot;static_page&quot;'> 
<p>Text for everywhere except static pages</p>
</b:if>

Specific URL Only

To display only on specific URL
<b:if cond='data:blog.url != &quot;http://www.tech-hacks.com/2011/06/all-about-blogger-conditional-tags.html&quot;'> 
<p>Text will display on above URL only</p>
</b:if>

Certain Labels Only

To display content on certain labels only:
<b:loop values='data:post.labels' var='label'>
<b:if cond='data:label.name == &quot;Testing Category&quot;'>
Text will be displayed only on Posts which have label Testing Category.
</b:if>
</b:loop>
Note*: You will need to be inside Blog Posts loop in order to use Certain Labels Only code 
Share this article :

Post a Comment

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Make Money Online - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger