November 11, 2008

If you’re a theme developer you have almost certainly noticed that the WordPress template tag, next_post_link, can be set up in two ways: to link to the next post, or the next post within the same categories as the current post. This attests to an obvious truth, that what a user wants, or expects, to happen on your blog, will change depending on what they are doing. Modes are a basic method of detecting these intentions.

What is a mode?

A mode is actually very simple. As a visitor moves through your site they will do so in a few different ways. They may link from post page to post page, sort by tag, sort by category or run a search. Depending on whether they are browsing, seeking, or searching their needs will differ.

A mode is a change in the way your theme works to try and meet those needs. So your theme may be in search mode, category mode, tag mode, or browse mode, at any one point in time.

What can I do with modes?

In the introduction I mentioned the template tag next_post_link can work in different ways. In category mode you would expect the user to work backwards through the posts in the category they have selected. The same applies for tag mode.

In search mode they may want access to their search results so they can view each one in turn without having to click back, or open new tabs.

In browse mode it may simply be enough to record the posts they have visited so that when they move modes they aren’t presented with the same posts that they have already seen. For example, If they browse through 5 posts before hitting a category page then presenting visited posts in a separate list from the non-visited posts might let find so much more.

What you do and how you do it is up to you, but there is ample room for you to be imaginative, and to surprise your visitors with the excellent new functionality that is available.

How do I implement modes?

How simple or complex you want your mode switch to be is up to you. At its most simplest all you need do is check the page the users is on and, if that page meets certain conditions, switch mode accordingly.

A very basic mode mode function might look a little like this:

[php]
function get_mode(){
global $post;

$current_mode = array();
$current_mode[0] = ( isset($_SESSION['my_theme_mode']) ) ? $_SESSION['my_theme_mode'] : 'browse';

switch( $current_mode[0] ){
case 'category':
$current_mode[1] = $_SESSION['my_theme_mode_category'];
break;
case 'tag':
$current_mode[1] = $_SESSION['my_theme_mode_tag'];
break;
case 'search':
$current_mode[1] = $_SESSION['my_theme_mode_search'];
break;
case 'browse':
$current_mode[1] = $_SESSION['my_theme_mode_browse'];
break;
}

//if is category, do it
if ( is_category()){
$_SESSION['my_theme_mode'] = 'category';
$_SESSION['my_theme_mode_category'] = single_cat_title("", false);
$current_mode[0] = 'category';
$current_mode[1] = single_cat_title("", false);
} elseif ( is_tag()){
$_SESSION['my_theme_mode'] = 'tag';
$_SESSION['my_theme_mode_tag'] = single_tag_title("", false);
$current_mode[0] = 'tag';
$current_mode[1] = single_tag_title("", false);
} elseif ( is_search()){
$_SESSION['my_theme_mode'] = 'search';
$_SESSION['my_theme_mode_search'] = get_search_query();
$current_mode[0] = 'search';
$current_mode[1] = get_search_query();
} elseif ( is_home() ) {
$_SESSION['my_theme_mode'] = 'browse';
$current_mode[0] = 'browse';
}

if ( is_single() ) {
$browse_array = $_SESSION['my_theme_browsed_posts'];
$browse_array[] = $post->ID;
$_SESSION['my_theme_browsed_posts'][] = $browse_array;
}

$current_mode[2] = ( isset($_SESSION['my_theme_browsed_posts']) ) ? $_SESSION['my_theme_browsed_posts'] : array() ;

return $current_mode;

}

A few posts ago I argued that posts shouldn’t be made more flexible, but more intelligent. Modes is one way to kick this off. What kid of changes would you want to see from an intelligent theme?



Wordpress title showing space?
no comment on page 1371

Wordpress fun?
one comment on page 1376

Live blogging plugin?
4 comments on page 1258

Wordpress 3 admin speed up?
4 comments on page 1321

Framework photoshop?
3 comments on page 296

Fun wp plugins?
one comment on page 1376

Habari vs wordpress?
12 comments on page 440

Wp tags vs categories?
12 comments on page 7

Wordpress rss seo?
one comment on page 1361

Photo albums html5?
6 comments on page 1305

Wordpress chat?
no comment on page 1308

Wordpress exif data?
12 comments on page 230

Css sidear tab?
2 comments on page 336

Wordpress theme html5 blueprint?
6 comments on page 1305

Wordpress shortcode in plugin?
no comment on page 236

Html 50 photo album?
6 comments on page 1305

Get the post attachement?
24 comments on page 1065

Wordpress plugin development 30?
one comment on page 1373

Wordpress plugin development 30?
one comment on page 1373

Disqus formatting?
7 comments on page 1175

Html5 photoalbum?
6 comments on page 1305

Html5 photoalbum?
6 comments on page 1305

Wordpress fun?
one comment on page 1376

Fun wordpress plugins?
one comment on page 1376

Url shortener ideas?
4 comments on page 1190

Url shortener ideas?
4 comments on page 1190

Html 5 photo gallery?
6 comments on page 1305

Multiple post navigation?
no comment on page 1147

Html5 photo galleries?
6 comments on page 1305

Adding images to a wordpress 3 post?
24 comments on page 1065

Html5 photo gallery code?
6 comments on page 1305

Wordpress multiple blog master?
one comment on page 1376

Wordpress 3 tableprefix?
one comment on page 1376

Wordpress 3 tableprefix?
2 comments on page 1374

Using wordpress as a framework?
2 comments on page 335

Single post image size?
24 comments on page 1065

Get featured image src wordpress?
24 comments on page 1065

Disqus wordpress mu?
7 comments on page 1175

Image gallery html 5?
6 comments on page 1305

Wordpress theimage?
24 comments on page 1065

Wpgetattachmentimagesrc size?
24 comments on page 1065
  every 1740s, 1s ago, in 0.03s.
 __
(__)
   `
 female

Has read with the pleasure, very interesting post, write still, good luck to you!


0s