sean@dluxstudios.com

DLUXstudios.com is the creative practice of Art Director, Designer & Illustrator Sean Gallagher. Sean lives & works in New York. He likes skateboarding & Robochan.

Styling Single page views in Wordpress

September 4th, 2009

I just came across this article that shows a great way to Style different views of or the “single” view, Single.php in Wordpress. In the wordpress template structure hierarchy, “single” is the end of the line for a individual item of content form the timeline based view or “blog” view. Sometimes written content, like news articles should appear differently than say, a photo gallery post. Or maybe you have visual content and want it in a slick jQuery slide show, and need it handled differently.

This article : http://wordpressgarage.com/tips/displaying-single-post-pages-differently-in-specific-categories goes over some great methods for using the default Single.php file as a way of determining which category you are viewing, and then which special categorical version you would like to use there after to display your special content.

You replace your php in Single.php with this nice little conditional statement. A conditional is just like it sounds “IF” certain criteria is met, in this case a certain category’s content is being browsed to the single view, “THEN” pass it off to this other special file that deals with that content in a certain way. “ELSE” if it is in this OTHER category pass it to this OTHER view instead.

Check it:

Inside of the original single.php, delete everything and replace it with this:

<?php
$post = $wp_query->post;
if ( in_category('9') ) {
include(TEMPLATEPATH . '/single2.php');
} else {
include(TEMPLATEPATH . '/single1.php');
}
?>

From here you would make a Single1.php file.

This is great as you can separate these views and easily manage their differences or assign them their own unique CSS files.

I highly recommend checking this article out.

Leave a Reply

You must be logged in to post a comment.