Tech Tips on Computers, Internet, Blogging, Web Development, Social Media, Android and more

Full width home advertisement

Post Page Advertisement [Top]

common useful blogger conditional statements

If you are a Blogger user, there may come a time when you need add code directly in the Blogger theme. Although, I recommend to add code in HTML/Javascript gadget/widget as far as possible because it is easier to manage in layouts. But if adding code in HTML/Javascript does not work the way we want, we have to edit the Blogger theme. In which case, we will end use using some conditions to apply such as if I want to display certain thing only on the home page or only on static item page etc. Here are some useful Blogger conditional statements.

Blogger condition to check if home page

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

Blogger condition to check if post page
<b:if cond='data:blog.pageType == "item"'>
</b:if>
<b:if cond='data:blog.pageType == "static_page"'>
</b:if>

Blogger condition to check if first post on the home page
<b:if cond='data:post.isFirstPost'>
</b:if>

Blogger condition to check if Archive page
<b:if cond='data:blog.pageType == "archive"'>
</b:if>

Blogger condition to check if specific page
<b:if cond='data:blog.url == "your-url-here"'>
</b:if>

Blogger condition to check if label page
<b:if cond='data:blog.searchLabel'>
</b:if>

Blogger condition to check if error page
<b:if cond='data:blog.pageType == "ERROR_PAGE"'>

Blogger condition to check if mobile page
<b:if cond='data:blog.pageType == "data:blog.isMobile"'>

How to use the above conditions:
<b:if cond='data:blog.url == data:blog.homepageUrl'>
<!--  Add your code or text here which will  appear if the above condition is true -->
</b:if>

If if-else condition is required:
<b:if cond='data:blog.url == data:blog.homepageUrl'>
<!--  Add your code or text here which will  appear if the above condition is true -->
<b:else/>
<!--  Otherwise, add your code or text here which will  appear if the first condition is not true-->
</b:if>

Not condition example:
<b:if cond='data:blog.pageType != "index"'>
<!--  Add your code or text here which will  appear if the above condition is true -->
</b:if>


No comments:

Post a Comment

Bottom Ad [Post Page]