Often times in comments for my Blogger tutorials on this blog, I am asked “how do I make this work only on posts and not pages?” or similar questions relating to having widgets or scripts only appear on certain areas of the site.
There is a way to only make your content appear on certain selected sections of a Blogger template, but you need to use something called Conditional Tags.
Before jumping into this, note that this technique is a bit more advanced. If you have trouble understanding HTML you will want to be careful when editing your template with code. You can try playing around with these options on a test blog until you feel comfortable implementing them into your own.
Blogger has a bunch of conditional tags you can use to target specific pages. Here is a list of them below:
Includes: home page, label pages, and yearly archive pages
Includes: the home page only
Includes: single posts (i.e. when you open up a single post to read)
Includes: posts in your archive, older/newer posts pages
Includes: pages that are accessed through the label cloud or list and in your post footer
Search Query Pages
Includes: pages that are accessed using the Search widget function
Includes: your error page when a post is not found or doesn’t exist
Includes: a specific page that you supply. Enter your URL in the code below
Includes: only the first post shown on your blog. Does not include pages.
These codes can be used anywhere inside of your template’s HTML page, excluding inside of a <b:section> or <b:widget> tag. If you only want a Linkwithin widget to appear on individual post pages, for example, you would use this code in the place you want your Linkwithin widget to appear in your template (usually in the post footer)
All you need to do is put the content between the conditional tags as shown above.
If you want to exclude a page or post, you might want to reverse a condition. This means that the content you specify will only appear on pages other than the one you’ve included in the tag. You would simply implement a reverse condition like so:
All we did was change the == to != in the code above. Instead of saying “if this page is equal to the item” we have changed it to “if this page is not equal to the item”.
This may seem confusing at first, but once you get the hang of it, these conditional tags can be extremely useful!