health

business

vehicles

technology

How To Use Blogger Conditional Tags

How To Use Blogger Conditional Tags

Knowing how to use conditional tags in Blogger is amazing because it allows you to do everything from hiding certain widgets, to removing extra scripts. Blogger allows you to create a very fast loading and unique looking site through the use of these conditionals.

Conditional Tags can allow you to hide extra JavaScript like we are doing, or building a unique looking homepage. You can do a lot with conditionals and by learning how to use them effectively you are going to make a very powerful and professional looking site.

1. Conditional Tags For Homepage

This tag is used for the homepage of your blog. It will tell a widget or a piece of code to load on the homepage of your blog.

<b:if cond='data:blog.url == data:blog.homepageUrl'> Homepage </b:if>

 2. Post and Static Page Conditional Tags

This tag works on both pages and posts in your blog.
<b:if cond='data:blog.url == data:post.url'> Posts & Pages </b:if>

3. Posts Only

This will only load the widget on posts.
<b:if cond='data:blog.pageType == "item"'> Posts</b:if>

4. Static Page Conditional Tag

This will only load the widget or scripts on pages.
<b:if cond='data:blog.pageType == "static_page"'> Pages </b:if>

5. Index Page Conditional Tag

Index pages are pages that show blog posts on typically in multiple locations. For instance the homepage, label page, query pages, and yearly archive pages. 

<b:if cond='data:blog.pageType == "index"'>  Index </b:if>

6. Label Page Conditional Tag

Label pages are the tags that you apply to posts here is the code to load conditionally on them.
<b:if cond='data:blog.searchLabel'> Label </b:if>

7. Search Query Page Conditional Tag

Search Query pages are the pages that are returned whenever you use a search bar. You could use this query to remove the sidebar on the search pages or you could add an additional advertisement next to the search results!
<b:if cond='data:blog.searchQuery'> Search Query </b:if>

8. Archive Page Conditional Tag

The archive page is the date or month based archive that you find in your archive widget.
<b:if cond='data:blog.pageType == "archive"'> Archive Page </b:if>

First post conditional tab

This is not a page type but it actually targets the first post on an archive/index/label page.
<b:if cond='data:post.isFirstPost'> First Post </b:if>

9. Error Page Conditional Tag

The 404 page is typically a page that you don't have a sidebar on you could remove it with this conditional tag.

<b:if cond='data:blog.pageType == "error_page"'>  404 Error Page </b:if>

10. Conditional Tag for a Specific page/URL

<b:if cond='data:blog.url == "URL"'> Specific URL </b:if>

Reverse Condition

You can reverse the condition of Blogger conditional tags. For instance if you have a sidebar set to only show on the blog posts. You could say load this on everything but the blogposts. To do this all you need to do is change the == to != like the example below.

<b:if cond='data:blog.pageType != "item"'> Now everything but the posts will have whats in here </b:if>

Multiple Conditions

Let's say that you want to display a widget on the blog posts and the item pages instead of duplicating the code you could in theory wrap it in an if else statement.

<b:if cond='data:blog.pageType == "item"'>
EXECUTE IF TRUE
<b:else/>
EXECUTE IF FALSE
</b:if>
Now you are armed with all the tools to make proper use of Blogger's conditional tags so lets see what you can create or optimize!

No comments: