Have you ever think why some Display Elements show only or not show on specific Page? Or Specific Post? Or Have you ever heard about Conditional tags?
Have you ever been confusing with like that codes in your Blogger template HTML? Or looking for what are they?
<b:if cond='data:blog.pageType != "static_page"'>
<b:if cond='data:blog.pageType != "item"'>
<b:if cond='data:blog.pageType != "item"'>
Above codes are conditional tags.
When you are studying your blog template especially, if you are using the professional (third party) template, Have you ever think that how some certain elements or widgets appear only on certain types of pages?
Some certain widgets or elements of your template appear on the home page, but not on individual post pages also, sometimes sidebars appear on the homepage but not on individual post pages.
Also, if you are designing your Blogger template, you may prefer certain widgets or elements of your design to appear on certain types of pages or on the home page & not on individual post pages & you would prefer to display different buttons on different pages or apply a meta tag only to selected pages?
I will explain how you can easily control page elements to display or not on certain types of pages in your Blogger blog. For do that we use Conditional tags to edit our blog template. Conditional tags are Blogger template tags that allow you to specify parts of your template to appear only under certain conditions. That provides us better control over our templates, allowing us to specify what part of our template appears only under certain conditions.Some certain widgets or elements of your template appear on the home page, but not on individual post pages also, sometimes sidebars appear on the homepage but not on individual post pages.
Also, if you are designing your Blogger template, you may prefer certain widgets or elements of your design to appear on certain types of pages or on the home page & not on individual post pages & you would prefer to display different buttons on different pages or apply a meta tag only to selected pages?
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, it will help you modify elements of your blog template.
But remember that Conditional tags work with all of the standard Blogger templates except Dynamic Views, which does not accept customization. Some third-party templates may not accept conditional tags, but most do.
Before knowing about the Conditional tags, it is better to know about different types of pages on your blogger.
What are the different types of pages on your blogger?
1) home page - It’s your blogs home page.
3) Item Page - Refers to Post Pages that created by clicking new post button (the individual
post page)
post page)
4) Index Page - Includes home page + label page + search results page. (pages readers see when they click the "Older Posts" and "Newer Posts” (links at the bottom of the page.)
5) Static Page - Blogger Pages created by clicking the new page button.
6) Label Page - Blogger label-based pages contain similar or related posted articles.
7) Search Page - Pages that provide a list of posts that matches the given query terms.
What are Conditional tags?
Conditional Tags are s Boolean data type that can be used in your blogger template to alter the display of content depending on the conditions that current page matches. Conditional tags tell Blogger what codes or content to display under specific conditions. That allows you to specify parts of your template to appear only under that certain conditions. If you applied conditional tags properly, Conditional tags can make all that happen correctly.
List of conditional tags for different types of pages
There are different conditions to check the page type. You can use these conditions for the selective display. The following are a select few conditional tags you'll require the most:
Home page:
<b:if cond='data:blog.url == data:blog.homepageUrl'>
First post:
<b:if cond='data:post.isFirstPost'>
Archive Pages:
<b:if cond='data:blog.pageType == "archive"'>
Specific page/URL:
<b:if cond='data:blog.url == "ENTER_URL_HERE"'>
Item page(post):
<b:if cond='data:blog.pageType == "item"'>
Static pages:
<b:if cond='data:blog.pageType == "static_page"'>
Index pages (includes homepage, label pages, search result pages and archive pages):
<b:if cond='data:blog.pageType == "index"'>
Archive pages:
<b:if cond='data:blog.pageType == "archive"'>
Posts and static pages:
<b:if cond='data:blog.url == data:post.url'>
Label-search pages:
<b:if cond='data:blog.searchLabel'>
404 Error Page:
<b:if cond='data:blog.pageType == "ERROR_PAGE"'>
Mobile Pages:
<b:if cond='data:blog.pageType == "data:blog.isMobile"'>
Particular URL only:
<b:if cond='data:blog.canonicalUrl == " PUT_URL_HERE"'>
How to use conditional tags to Display Elements only on specific Pages?
As we discuss the 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 provides 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)
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 an alternate content (when the condition is false), you need to insert a <b:else/> tag followed by the content,
<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 == "The_Particular_Page_Url"'>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 blog post 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 + "p/foo.html"'><!-- static_site foo OR static_site bar --><b:else/><b:if cond='data:blog.url == data:blog.canonicalHomepageUrl + "p/bar.html"'><!-- 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>
I Hope the above details help you to know what are the Conditional Tags? And How to use conditional tags to Display elements only on specific? And if you have any problem or know more on Conditional Tags, please share with us in the comments section below.