Leveraging Conditional Tags in Blogger Templates
- Blogger Style:
- Classic Templates
- Working with:
- Edit Html
There are a second set of Blogger template tags known as Conditional Tags which can allow you to specify what information to display under certain conditions. The Conditional Tags are dependant upon the page type you are viewing -- those types are the Main Page, Archive Page and Item Page. A fourth Conditional Tag is an "OR" combination of the Main/Archive pages.
<MainPage>
... show this on Main page only
</MainPage>
<ArchivePage>
... show this on Archive page only
</ArchivePage>
<ItemPage>
... show this on Item page only
</ItemPage>
<MainOrArchivePage>
... show this on Main or Archive page only
</MainOrArchivePage>
You can use any Conditional Tag more than once in your template. Mix and match them wherever you want to.
Practical Uses for Conditional Tags
Let's say that you want to display a short introduction of what your blog is about on your Main Page before your Posts start to be displayed.
<MainPage>
<h1>The Widget Factory Blog</h1>
<p>Hello and welcome to the Widget Factory,
a world of widget news, reviews and fun!</p>
</MainPage>
The introduction will not appear on any of your Item or Archive pages.
If you are listing your Recent Posts in the sidebar of your blog, then having them on your Main Page is a little redundant. Also, the list is of no real value on your Archive pages. Let's display the list on your Item Pages only.
<ItemPage>
<h3>Latest Entries</h3>
<ul>
<BloggerPreviousItems>
<li><a href="<$BlogItemPermalinkURL$>">
<$BlogPreviousItemTitle$></a></li>
</BloggerPreviousItems>
</ul>
</ItemPage>
Conditional Tags work in the <head> section as well. For example, take this following code snippet which alters the your Page Title.
Normally an Item Page will have a Title in the form of "Site Name - Post Title" which comes from the Template Tag <$BlogPageTitle$>. We can workaround this by using Conditional Tags.
In the <head> section, find this:
<title><$BlogPageTitle$></title>
Replace with this:
<MainOrArchivePage>
<title>Your Sitename - Site Description</title>
</MainOrArchivePage>
<ItemPage>
<title>
<$BlogItemTitle$> - Your Sitename</title>
</title>
</ItemPage>
As you can see, there are many uses for Conditional Tags. Try using this method for displaying your Blogroll on your Main Page only or putting a short description of your blog in the Item Pages only. You are only limited by your imagination.
0 comments :
Post a Comment