Hi all
I want to set up a conditional statement into your single.php script that detects what the requested category is and displays a different template.
Does anyone know how to do this.
thanks
Hi all
I want to set up a conditional statement into your single.php script that detects what the requested category is and displays a different template.
Does anyone know how to do this.
thanks
single posts can have multiple categories;
you can check if the single post is in a certain category with the conditional tag in_category()
http://codex.wordpress.org/Function_Reference/in_category
http://codex.wordpress.org/Conditional_Tags#A_Category_Page
Hi thanks for this but when I put the following code into my single.php outside the loop the post don't appear when you click through the link to view them.
<?php
if ( in_category('create') ) {
include 'single-create-2.php';
} elseif ( in_category('St Martins news') ) {
include 'single.php';
} else {
// Continue with normal Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
// ...
}
?>
http://stmartinoftours-org-uk.greenstrata.com/category/create-2/
Have I set this up wrong or am I missing something?
in_category() might not work outside the loop.
also the permalink looks a bit strange with the .../2011/01/400/
i receive a '500 internal server' error when clicking on the post title.
you could paste the whole code of single.php into a http://wordpress.pastebin.com/ and post the link to it here - so the code can be seen in its context.
This topic has been closed to new replies.