Page loading ..
The FREE Online Tips Blog
Twitter | Facebook | Yahoo | Google | Firefox | Gmail | Security | Tools | more..

How to Detect Home, Category, Post or Archive Pages in Wordpress Blogs Using Smarty ?

October 25, 2009 under Wordpress Tips, Blogging Tips Bookmark / Share this Tip..
Say NO to Virus



Convert VHS to DVD



Advertise here

Before going to the actual topic, a few words on Blogsome. Blogsome.com is an unique blogging platform that lets you set up a free blog powered by Wordpress. There are many other sites too that let you setup a free blog powered by Wordpress.

Then how is Blogsome unique from others?

Blogsome is unique in the sense it also gives you the option to tweak the theme and customize it in the way you like. For example this blog was started using this theme. It also lets bloggers to take a maximum of five backups of their theme files. To elaborate a bit about the backend engine of Blogsome here’s what The Uvular R, the Blogsome site admin has to say:

Blogsome actually runs on WordPress Cognotent (Cognotent being the name of the company which manages Blogsome). As the name indicates, this software is descended from WordPress, but it is different in a number of respects. This means that the WordPress documentation is sometimes inapplicable.

The Blogsome documentation is available here.

Blogsome.com logo

Well I sometimes wonder too like you about what am I doing here and why am I not moving to my own domain? Why am I not growing up? There are two reasons: 1) This is my first blog 2) There are numerous limitations at Blogsome and I find it really challenging to overcome those barriers and tweak the code in my own way, just like you. Their service is also quite satisfactory (except that they don’t upgrade the Wordpress version which is still 1.5.1-alpha)

A few years ago I showed how to make a customized 404 error page which is SEO friendly too. In this topic let us discuss on how to distinguish or detect home page, category page, post page, archive page.

We will be using the ‘REQUEST_URI’ variable and match it with a string. You may use the following codes anywhere in your index.html, posts.html, comments.html file. If you are unclear about the codes at first try it in your blog and see the output. If you are still unclear leave a note here.

1. Home Page

The URI of the home page looks like http://webtips.blogsome.com/ But while doing URI detection, we will be only considering the portion after TLD (.com) which in this case is /. So to detect a home page we have to check whether the URI of the page is ‘/’.

{if $smarty.server.REQUEST_URI == '/'}This is the Home Page.{/if}

2. A Post or a ‘Page’

In both cases we need to match the exact URI we are trying to detect.

{if $smarty.server.REQUEST_URI == '/2006/09/15/javascript-webpage-preloader/'}This is a post.{/if}
{if $smarty.server.REQUEST_URI == '/javascript-website-preloader/'}This is a page.{/if}

3. Category Page

The URI of a category page looks like /category/blogging-tips/ Now to check a category page we need to see if the first 10 characters of an URI is ‘category’. We cannot consider the category name since it may vary.

{if $smarty.server.REQUEST_URI|truncate:10:'':true == '/category/'}This is a category page.{/if}

4. Archive Page

The URI of an archive page looks like /2009/06/ (i.e. /yyyy/mm/) To check an archive page we need to see if the number of characters in the REQUEST_URI variable is 9.

{if $smarty.server.REQUEST_URI|count_characters == '9'}This is an archive page.{/if}

How to use the code for theme optimization?

You may use these codes in various ways. For example check the post header font size in the home page and in post pages.

Hope these tips help you in your blogging endavor at Blogsome. If your blog is not hosted at Blogsome and you still want to use these codes, just ask Google on how to convert the codes into your blog’s native language.

3 Responses to How to Detect Home, Category, Post or Archive Pages in Wordpress Blogs Using Smarty ?

uberVU - social comments on October 26, 2009

Social comments and analytics for this post

This post was mentioned on Twitter by ramnath: Blogging Tips: How to Detect Home, Category, Post or Archive Pages at Blogsome Using Smarty ? http://bit.ly/10ZTpI… http://bit.ly/O7XOb

Ravi on October 26, 2009

Nicely documented. Also searching for similar items, found this http://bit.ly/2POx1M; very similar but a different approach to a few tags.

Home Refinancing on November 14, 2009

Thank you very much. I appreciate website your help my life. That is very kind of you.

Leave a Reply »

For any queries mail us at: rabanerjee@gmail.com




Keep Discovering WebTips » 2 | 3 | 4 | 5



Blog Desiged & Programmed by Ramnath | Launch your free blog at Blogsome

Powered by WordPress


Monitored by Pingdom