Follow this Blog!

Aug 18, 2010

f Comment

How To Tell The Page Type In Google Blogger's Template Language?

Amazon In Google Blogger's template HTML I'd like to be able to tell what page type the current page is so I can treat it accordingly. The template is constructed with Blogger's own syntax, tags and attributes. What's the syntax and what does each special tag mean? Read on to find answers to all these questions in MINUTES!

First of all here's a screen shot of the Blogger template HTML editor user interface:

Blogger Template HTML Editor Window

The text area is where you edit the template HTML so that your blog displays what you want it to display. All pages on your blog share this template, so if you want to treat pages differently according to their page type you need to create such conditional statements. For example you may want the homepage to contain a pitch line that you don't want other pages to contain; you may want label pages to simply list links to the corresponding posts without showing the actual post bodies; etc.

Here's the deal: How do you know whether the current page is the homepage, a single post, a static page, an archive page, or a label page? What condition do I need to test? You need to be able to make this distinction to treat each type of page differently. Surprisingly the Blogger documents and references regarding widget tags for layouts and page elements tags for layouts do NOT address this question thoroughly. They merely say

data:blog.pageType specifies the type of the current page. One of 'item', 'archive', or 'index'.
And it says nothing about what each value means. How frustrating Some values are obvious but others aren't. After some digging I figured out the following (value:meaning):

index : homepage such as or label page such as
item : item page such as
static_page : static page such as
archive : archive page such as

To tell homepage and a label page apart test whether data:blog.url equals data:blog.homepageUrl. If so then this is the homepage. Otherwise use data:blog.pageType. Here's the complete code that has a condition block for each page type:
<b:if cond='data:blog.url == data:blog.homepageUrl'>
<!-- homepage -->
  <b:if cond='data:blog.pageType == &quot;index&quot;'>
  <!-- label page -->
    <b:if cond='data:blog.pageType == &quot;item&quot;'>
    <!-- single blog post -->
      <b:if cond='data:blog.pageType == &quot;static_page&quot;'>
      <!-- static page -->
        <b:if cond='data:blog.pageType == &quot;archive&quot;'>
          <!-- archive page -->
            <!-- unknown page; shouldn't be possible -->
Now you should be able to distinguish among the page types of your blog. Questions? Let me know!
Please leave a comment here!
One Minute Information - by Michael Wen
Find Michael on Google or Facebook
ADVERTISING WITH US - Direct your advertising requests to Michael