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 get image from post?
25 comments on page 1065

Photo gallery html5?
6 comments on page 1305

I use wpunlimited theme?
3 comments on page 1141

Slidebar image gallery html5?
4 comments on page 1053

Html5 photo gallery code?
6 comments on page 1305

Wpgetattachment?
25 comments on page 1065

How do you style polldaddy css?
2 comments on page 42

Disqus themes?
7 comments on page 1175

Css log in screend?
no comment on page 128

Is wordpress a framework for php?
2 comments on page 335

Wordpress featured images?
25 comments on page 1065

Wordpress featured images?
25 comments on page 1065

Disqus add image in comment?
7 comments on page 1175

Wpcache?
9 comments on page 1310

Funny wordpress plugins?
2 comments on page 1376

Css login screen?
no comment on page 128

Photoshop framework?
4 comments on page 296

Wpfun?
2 comments on page 1376

Wordpress fun plugins?
2 comments on page 1376

Get alll images of post wordpress?
25 comments on page 1065

Gallery html5?
6 comments on page 1305

Customisable short url?
4 comments on page 1190

Wordpress featuredimage?
25 comments on page 1065

Wp multiple sites?
one comment on page 1367

Wpupdatepost not working?
no comment on page 122

Html5 photo gallery code?
6 comments on page 1305

Html5 photo gallery code?
6 comments on page 1305

Flexx theme review?
4 comments on page 1026

Css login screen?
no comment on page 128

Show image in post?
25 comments on page 1065

Html5 image gallery?
6 comments on page 1305

Wordpress get post image?
25 comments on page 1065

Html 5 gallery?
6 comments on page 1305

Wpgetattachmentimagesrc?
25 comments on page 1065

Getimagefrompost resize?
25 comments on page 1065

Fun wordpress?
2 comments on page 1376

Wordpress workflow?
3 comments on page 1226

Easy peasy images featured image?
25 comments on page 1065

Google charts tinymce plugin?
7 comments on page 71

Html5 photo gallery code?
6 comments on page 1305

Simple css login screeen?
no comment on page 128

Wp flexx?
4 comments on page 1026
  every 1721s, 1s ago, in 0.03s.
 __
(__)
   `
 female

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


0s