Limiting Previous Posts LinksFiled Under: Themery
I want to share with you one of the features that I included in the WordPress theme that I released yesterday, or at least my thinking behind it, because it is something that I thought about for a while before implementing. The features is tracking the user on certain pages to determine the type of links to offer.
When you include a previous, or next, post link in a template file you have the option of limiting the link to posts in the same category, and of limiting those categories to ensure that some are excluded from that.
The problem I have found with my themes is that hard coding this into the theme meant I was either limiting posts to categories when I didn’t want to, or I wasn’t limiting posts when I thought the user would probably expect it.
So, the user might select a category list and get an archive page. From that page they select a single post to view. If the user then chooses a newer or older post do they expect it to be restricted, or not? I thought so.
My solution was to offer a choice, but only under certain circumstances.
When a user visits a category page, the ID of that category is saved into a session variable. If they next visit a single page that is in that category, the category is retained; otherwise it is discarded.
If a user is viewing a single page and their session variable contains a category ID they are presented with a choice. Select a older or newer post from that category, or select an older or newer post from the blog as a whole.
If they do not have the session variable then they do not get the choice, they are automatically taken to the newer, or older, post from the blog as a whole.
I think this is a good way of meeting the users needs unobtrusively.
- Permalink
- Andrew Rickmann
- 14 Apr 2008 4:50 PM
- Comments (0)