
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.
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.
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 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?
(__)
`
Has read with the pleasure, very interesting post, write still, good luck to you!