Currently Browsing: Templates

Use a shortcode in WordPress template files

Shortcodes are designed to allow you to call certain plugin or built in theme functions within the post/page editor. This code snippet allows you to use shortcodes in a template file as well.

Use different single post templates based on category

Need your single post views to be totally different depending on what category the post is in? You can do this easily by creating special single post files for each category as needed, and then replace the code in your single.php file with the following:

 <?php
if (in_category('jobs')) {
     include(TEMPLATEPATH . '/single1.php');
} elseif (in_categorye('News')) {
    include(TEMPLATEPATH . '/single2.php');
} else {
     include(TEMPLATEPATH . '/single3.php');
}
?>

Obviously if you only have one special category you won’t need the “elseif” statement in the middle.
Check the conditional tags reference in the Codex if you need to control the single post template by something other than category such as tag, post number, etc.