Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Blogger: 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>
<b:if cond='data:blog.pageType == "archive"'>
<!--archive_Page-->
</b:if>
<b:if cond='data:blog.pageType == "error_page"'>
<!-- all error pages-->
</b:if>
<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>
<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>
<b:if cond='data:blog.searchLabel'>
<!-- all label pages -->
</b:if>
<b:if cond='data:blog.searchLabel == "foo"'>
<!-- for label 'foo' -->
</b:if>
<b:if cond='data:blog.searchQuery'>
<!-- all search pages -->
</b:if>
<b:if cond='data:blog.searchQuery == "foo"'>
<!-- for query 'foo' -->
</b:if>
<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>
@ptaferner

This comment has been minimized.

Show comment Hide comment
@ptaferner

ptaferner Nov 27, 2015

Hab grad ewig an der richtigen Syntax für eine spezifische Page gearbeitet, bis mir Google dein Gist ausgespuckt hat - vielen Dank :-)

Hab grad ewig an der richtigen Syntax für eine spezifische Page gearbeitet, bis mir Google dein Gist ausgespuckt hat - vielen Dank :-)

@henriquebarcelos

This comment has been minimized.

Show comment Hide comment
@henriquebarcelos

henriquebarcelos Mar 13, 2016

Perfect! Solved my problem trying to style a page out of the canonical url! Thanks!

Perfect! Solved my problem trying to style a page out of the canonical url! Thanks!

@henriquebarcelos

This comment has been minimized.

Show comment Hide comment
@henriquebarcelos

henriquebarcelos Mar 21, 2016

How can I use labels with space in the conditionals? I'm trying but only one word worked! :(

How can I use labels with space in the conditionals? I'm trying but only one word worked! :(

@peterfabian

This comment has been minimized.

Show comment Hide comment
@peterfabian

peterfabian Mar 25, 2016

using a similar condition as outlined above, in particular:
<b:if cond='data:blog.canonicalUrl == data:blog.canonicalHomepageUrl + &quot;p/splash.html&quot;'>

but it stopped working couple days ago. Do you guys also face this problem by any chance?

using a similar condition as outlined above, in particular:
<b:if cond='data:blog.canonicalUrl == data:blog.canonicalHomepageUrl + &quot;p/splash.html&quot;'>

but it stopped working couple days ago. Do you guys also face this problem by any chance?

@peterfabian

This comment has been minimized.

Show comment Hide comment
@peterfabian

peterfabian Mar 25, 2016

Just as a reply to myself, it doesn't work anymore. Suggestion for a workaround: use data:blog.pageId or data:blog.postId... via https://productforums.google.com/forum/#!category-topic/blogger/qsCuqtzvznM

Just as a reply to myself, it doesn't work anymore. Suggestion for a workaround: use data:blog.pageId or data:blog.postId... via https://productforums.google.com/forum/#!category-topic/blogger/qsCuqtzvznM

@shaneapen

This comment has been minimized.

Show comment Hide comment
@shaneapen

shaneapen Apr 14, 2016

I have created a blogger conditional tag wrapper tool using these tags provided. You can use it here-http://codegena.com/generator/blogger-conidtional-tag-wrapper

I have created a blogger conditional tag wrapper tool using these tags provided. You can use it here-http://codegena.com/generator/blogger-conidtional-tag-wrapper

@anovsiradj

This comment has been minimized.

Show comment Hide comment
@anovsiradj

anovsiradj Jun 8, 2016

instant bookmark! 👍

instant bookmark! 👍

@codiblog

This comment has been minimized.

Show comment Hide comment
@codiblog

codiblog Sep 29, 2016

Thanks to share but You have not added all conditional tags. Below link help people to find All Blogger Conditional Tags and How to use them correctly.
http://www.codiblog.com/2016/09/blogger-conditional-tags.html

Thanks to share but You have not added all conditional tags. Below link help people to find All Blogger Conditional Tags and How to use them correctly.
http://www.codiblog.com/2016/09/blogger-conditional-tags.html

@RapurHarishBabu

This comment has been minimized.

Show comment Hide comment
@RapurHarishBabu

RapurHarishBabu Oct 17, 2016

specific static page is not working for me 👎 Can anybody help me on this topic please.....

specific static page is not working for me 👎 Can anybody help me on this topic please.....

@yashas123

This comment has been minimized.

Show comment Hide comment
@yashas123

yashas123 Apr 2, 2017

Thanks a lot for the post!

Thanks a lot for the post!

@knigulper

This comment has been minimized.

Show comment Hide comment
@knigulper

knigulper Sep 26, 2017

data:post.thumbnailUrl is not mentioned here

data:post.thumbnailUrl is not mentioned here

@yeslearners

This comment has been minimized.

Show comment Hide comment
@yeslearners

yeslearners Sep 29, 2017

Can you help me to include a code in "blog posts with a specific label" please?

Can you help me to include a code in "blog posts with a specific label" please?

@sxanyar

This comment has been minimized.

Show comment Hide comment
@sxanyar

sxanyar Jan 24, 2018

Nice simple post, easy to understand!

sxanyar commented Jan 24, 2018

Nice simple post, easy to understand!

@RahulSaini91

This comment has been minimized.

Show comment Hide comment
@RahulSaini91

RahulSaini91 Apr 24, 2018

thanks, found helpful for me

thanks, found helpful for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment