Conditional Tags Explained (for Blogger)

 

„Conditional“  tags enable us to dictate the type of page on which the enclosed content can be displayed. These tags are really quite useful in a number of ways. They are basically coding statements.
As you may know, with any condition you have a true, false and equal value.
Example:                                                                                                                  Earth rotates!                                                                                                            That statement is true! 

The basic variables you would see in a conditional statement are:
==     Equal to.
!=     Not Equal to.
===   Exactly Equal to.

There are more but those are the basics that you will use for most conditional statements.
If we were to write a conditional statement into a text sentence it would look something like this:

If today is Sunday I will go to church.

This is a conditional statement saying „I will go to church if today is Sunday“.
The condition is „If today is Sunday“.
The action if the condition is true (met) is „I will go to church“.  
I could also write it like this below.

Day of week == Sunday
I will go to church.

However, this is not a proper code to put in your template because statements need to be recognized and day of week and Sunday are not recognized without more coding to retrieve the date from the user´s computer.
Their are universal codes and tags that will be recognized without the need of any further coding needed. I will go over a few below.
The variables in all the examples below are all „Equal to“ but they can be changed to !=  (Not Equal) as well.

Homepage

In this example we will restrict the content within the „conditional“ tag to appear only on the homepage. This conditional tag does not work with the Not Equal (!=) tag.

<b:if cond='"data:blog.url == data:blog.homepageUrl"'>
<style>
<--Content to be displayed on homepage only -->
</style>
</b:if>

Static Pages

In this example we will restrict the content within the „conditional“ tag to be displayed only on the Static Pages.

<b:if cond='data:blog.pageType == "static_page"'>
<style>
<--Content to be displayed on static pages only -->
</style>
</b:if>

Post Pages

In this example we will restrict the content within the „conditional“ tag to be shown only on the Post Pages.

<b:if cond='data:blog.pageType == "item"'>
<style>
<--Content to be displayed on static pages only -->
</style>
</b:if>

Specified Page

In this example we will restrict the content within the „conditional“ tag to appear only on the Specified Pages.

<b:if cond='data:blog.url == "Blog Post URL"'>
<style>
<--Content to be displayed on specified page only -->
</style>
</b:if>

(In the example above you must fill in the Blog Post URL with the URL of your chosen page or post.)

That´s all for this time.

Good luck!

0 Comments:

Post a Comment