wordpress multiple single page

162 views Asked by At

Hi I have this function to call a simple page template I have created for the category event, which works great, but I'm struggling to format the function code correctly to add more, i thought it would be a question of adding elseif statement, but I can;t get it to work - can anyone educate me?

function get_custom_cat_template($single_template) {
global $post;
if ( in_category( 'Event' )) {
  $single_template = dirname( __FILE__ ) . '/single-event.php';
}

return $single_template;
} 
add_filter( "single_template", "get_custom_cat_template" ) ;
1

There are 1 answers

0
KAGG Design On

Try something like that:

function get_custom_cat_template($single_template) {
global $post;
if ( in_category( 'Event' )) {
  $single_template = dirname( __FILE__ ) . '/single-event.php';
}
elseif ( in_category( 'Dinner' )) {
  $single_template = dirname( __FILE__ ) . '/single-dinner.php';
}
elseif ( in_category( 'Show' )) {
  $single_template = dirname( __FILE__ ) . '/single-show.php';
}

return $single_template;
}

add_filter( "single_template", "get_custom_cat_template" ) ;