Diane Kern’s Insight Center needed an overhaul design-wise and navigation-wise. Diane wanted a few “books” or “blogs” and when that book/blog was on the page, the sidebars should change accordingly. Partly to explain how I did this, partly so I don’t forget myself, I’ll put some notes here about how I did this.

For example, for the book, Where Psychology Meets Physics, Diane wanted the “chapters” (posts) of that book to be listed in the left sidebar (in reverse chronological order so her first chapter would be on top. Custom Query String Reloaded came in handy to reverse-order the posts and the ridiculously powerful Customizable Post Listings allowed me to reverse-order (ASC) the sidebar posts. So far so good.

But then if we’re in a category, Diane wanted the category name to be in the header, under the name of the site. Hmm. I started out with three header files (one for each category), but then I realized I could call the category name just using some PHP:

[PHP]< ?php foreach((get_the_category()) as $category) { echo $category->cat_name . ‘ ‘;
}
?>[/PHP]

Just about the same technique to use the category description as something of an introduction to the books/categories:

[PHP]< ?php foreach((get_the_category()) as $category) { echo $category->category_description . ‘ ‘;
}
?>[/PHP]

While I did create three sidebars for the different categories, I did think to use widgetized sidebars so I just changed the number of sidebars in the functions.php file:

[PHP]if ( function_exists(‘register_sidebars’) )
register_sidebars(8);[/PHP]

and then told those files to look for sidebars 1 and 2, 3 and 4, 5 and 6, and finally 7 and 8 (for the main sidebars and then one set (left and right) for each category).

I thought I was about done until I clicked on a single post in a category. Ugh, there went my custom sidebars and headers. I then altered my single.php file according to Lorelle and created three single templates for each of the three categories (sidebar-6.php, sidebar-8.php, sidebar-9.php, based on the category IDs). Then my single.php file became just this:

[PHP]< ?php $post = $wp_query->post;

if ( in_category(‘6’) ) {
include(TEMPLATEPATH . ‘/single-cat-6.php’);

} elseif ( in_category(‘8’) ) {
include(TEMPLATEPATH . ‘/single-cat-8.php’);

} elseif ( in_category(‘9’) ) {
include(TEMPLATEPATH . ‘/single-cat-9.php’);

} else {
include(TEMPLATEPATH . ‘/single-cat-6.php’);

}
?>[/PHP]

I made sure those single tempate files called the header file that had the category info:

[PHP]< ?php include (TEMPLATEPATH . '/header_cat.php'); ?>[/PHP]

and then also got the correct sidebar:

[PHP]< ?php include (TEMPLATEPATH . '/sidebar-6.php'); ?>[/PHP]

If I knew more what I was doing, I probably could have had more intelligent “if” clauses to save me the trouble of all of those sidebar and single files, but maybe next time.