Translate This Blog
Remember To Always Back Up Your Template Before Attempting Any Of The Tweaks On This Site

About "Conditional" Tags

"Conditional"  tags enable us to dictate the type of page in which the enclosed content can be displayed. They are really quite useful in many ways. Conditional tags are basically coding statements.

With any condition you have a true, false and equal value.

Example:
Sunday is a weekend!
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 may looks 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".

This 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 users computer.

Their are universal codes and tags that will be recognized without any farther coding needed. I will go over a few below.

I have equal to variables in all these below but they can be changed to !=  (Not Equal) as well.

  • Homepage
In this example we will restrict the content with in the "conditional" tag to display 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 with in the "conditional" tag to display 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 with in the "conditional" tag to display 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 with in the "conditional" tag to display 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 the page or post your choosing.)

Learn About Conditional "Else" Tags.

2 comments:

Michal said...

Hello. I'm wondering if conditional tags could be applied to opening links in an external window in combination with this tweak:

...expr:href='data:link.target' target="_blank">...

Specifically, can a conditional tage be used to open only external links in a new window? Such as, if the target domain is different from the source domain perhaps?

AiresOFwar said...

Hmmmm that would be a interesting way to use conditional tags! I am not aware of anyway to do so with these conditional tags. Their might be some JavaScript conditions that will allow you to do so but I am not a JavaScript programmer. I would recommend looking around on this site. If you can find it then sign up for the forums which will take a few days to be approved because they are privet forums. The forums on that site have many experts who can help.

Post a Comment

Please don't post hyperlinked text within the comment box! It will not be published and you will be marked as spam.

Web Design Blogs PageRank