Sunday, March 11, 2018

March 11, 2018

How to Use conditional tags?

How to Use conditional tags-

Conditional tags 2 ?


Hello my friends…!

As we discuss last post, you know that Conditional tags are Blogger template tags that allow you to specify parts of your template to appear only under certain conditions. That provide us better control over our templates, allowing us to specify what part of our template appears only under certain conditions.

 You may wish to hide a widget or element on one page and display it on the other, need to remove the sidebar on certain pages, or even display buttons on select pages. This is exactly where conditional tags come into play. There are a number of tags available for blogger which, if applied correctly, will help you modify elements of your template.

* Before you edit template HTML first you need to Back up your template.

1.Only or Not

The double equals " == " actually means TRUE. You can change the condition to FALSE, then just replace the first equal with an exclamation sign: " != ".

You might like to display only on the home page .. ( TRUE)
<b:if cond='data:blog.canonicalUrl == data:blog.canonicalHomepageUrl'>

Displaying on all pages other than the homepage (FALSE)
<b:if cond='data:blog.canonicalUrl != data:blog.canonicalHomepageUrl'>
   


2.  How to apply & Displaying something on conditional tags?

To apply a conditional tag to a content, simply put the content between the opening <b:if cond…> and the closing </b:if>

<b:if cond='THE CONDITION TAG'>
..Enter Content Here..
</b:if>


Example:

You might like to display a welcome message on the home page only. (TRUE)

<b:if cond='data:blog.canonicalUrl == data:blog.canonicalHomepageUrl'>
Welcome to my Blog
</b:if>

Displaying on all pages other than the homepage (FALSE)

<b:if cond='data:blog.canonicalUrl != data:blog.canonicalHomepageUrl'>
This is not the homepage but others.
</b:if>



3.Combining Conditions Together:

use two or more conditions 

<b:if cond='data:blog.pageType == "item"'>
<b:if cond='data:blog.url != "URL_OF_POST_TO_EXEMPT"'>
...ENTER CONTENT HERE...
</b:if>
</b:if>



4.If you want to specify a alternate content (when the condition is false),you need to insert a <b:else/> tag followed by the content,
like this:


<b:if cond='data:blog.pageType == "item"'>
ENTER CONTENT 1 (TO BE EXECUTED IF CONDITION IS TRUE)
<b:else/>
ENTER CONTENT 2 (TO BE EXECUTED IF CONDITION IS FALSE)
</b:if>


You can place the conditional anywhere in your template HTML, except inside a section or inside a widget content box. The content can be a div, a section, a style tag, another conditional tag.



5.Wrapping a widget with the conditional tags

Every widget other than the Blog post Widget has this general structure like below,


<b:widget id='something' locked='' title='' type=''>
<b:includable id='main'>
Somethings here
</b:includable>
</b:widget>



Wrapping conditional tags can be done as

<b:widget id='something' locked='' title='' type=''>
<b:includable id='main'>
<b:if cond='data:blog.canonicalUrl == &quot;The_Particular_Page_Url&quot;'>
Some things here
</b:if>
</b:includable>
</b:widget>



This code will display the widget on The_Particular_Page_Url only (you have to provide this url )

*Limitation-wrapping the blogpost widget is little complicated as it has many b:includables.



You can learn more details from below, there are some Globally conditional data tags for all page types.


#AND

<b:if cond='data:blog.pageType == "index"'>
  <b:if cond='data:blog.searchQuery'>
    <!--search_page AND index_page-->
  </b:if>
</b:if>



#OR

<b:if cond='data:blog.url == data:blog.canonicalHomepageUrl + &quot;p/foo.html&quot;'>
  <!-- static_site foo OR static_site bar -->
      <b:else/>
<b:if cond='data:blog.url == data:blog.canonicalHomepageUrl + &quot;p/bar.html&quot;'>
  <!-- static_site foo OR static_site bar -->
   </b:if>
</b:if>



#NOT

<b:if cond='data:blog.pageType != "index"'>
  <!-- all pages NOT index pages -->
</b:if>

<b:if cond='data:blog.url != data:blog.homepageUrl'>
  <!-- all pages NOT homepage -->
</b:if>


archive_page
<b:if cond='data:blog.pageType == "archive"'>
  <!--archive_Page-->
</b:if>

error_page
<b:if cond='data:blog.pageType == "error_page"'>
  <!-- all error pages-->
</b:if>

index_page
<b:if cond='data:blog.pageType == "index"'>
  <!-- all index pages -->
</b:if>

<b:if cond='data:blog.url == data:blog.homepageUrl'>
  <!-- only homepage -->
</b:if>


item_page
<b:if cond='data:blog.pageType == "item"'>
  <!-- all item pages -->
</b:if>

<b:if cond='data:blog.url == data:blog.canonicalHomepageUrl + "2014/08/foo.html"'>
  <!-- a item page from august 2014 with post-title 'foo'-->
</b:if>

label_page
<b:if cond='data:blog.searchLabel'>
  <!-- all label pages -->
</b:if>

<b:if cond='data:blog.searchLabel == "foo"'>
  <!-- for label 'foo' -->
</b:if>

search_page
<b:if cond='data:blog.searchQuery'>
    <!-- all search pages -->
</b:if>

<b:if cond='data:blog.searchQuery == "foo"'>
  <!-- for query 'foo' -->
</b:if>

static_page
<b:if cond='data:blog.pageType == "static_page"'>
  <!-- all static pages -->
</b:if>

<b:if cond='data:blog.url == data:blog.canonicalHomepageUrl + "p/foo.html"'>
  <!-- a specific static page with name 'foo' -->
</b:if>

Then ok my friends. I think now you have a better idea about  Usage of conditional tags.

How to Hiding Sidebar in Post Page??...>>>


For more reading THEWONDERSPOT

........................................................................................................................................................................................................................
EMoneySpot  -  Earn with us..........................................................................................>>>
........................................................................................................................................................................................................................

 How to earn money online.......................................................................................>>>

Improve organic SEO rankings while EARN MONEY (0.05/0.10$) per view.......>>>

How to take screenshots in windows 10 : Different Methods?................................>>>

Free Bandwidth Monitoring Tools For windows PC?.............................................>>>

Abnormally high internet bandwidth usage, c-0001.c-msedge.net of window 10....................>>> 

How to Speed up Internet connection on Windows 10..............................................................>>>

How to Disable Automatic Updates in Microsoft Office 2016?.................................................>>>

How to Disable Automatic Updates in Microsoft Office 2016?..................................................>>>

How to Block Windows 10 "Spying"? ........................................................................................>>>

How to start a Blog?.....................................................................................................................>>>

How to Choose the Best Blogging Platform, advantages & disadvantage.................................>>>

How to make your blog SEO friendly?........................................................................................>>>


All in one SEO pack for Blogger blog.........................................................................................>>>

Thank you for reading.
Good Luck.

Don’t forgot to Subscribe us to get latest news letters and give your feedback in below comment section ;-) ;-)

0 comments:

Post a Comment

Thank you for visit us.
Give your feedback. Don't worry. Your email is safe with us.
Subscribe us to get latest news letters.

amazon

 
Copyright © The WonderSpot All Right Reserved
Powered by Blogger