Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End make permalink go to a custom single.php file in WordPress Reply To: make permalink go to a custom single.php file in WordPress

#148215
luchid
Participant

Hello all, I solved a part of my problem by adding in my function.php this function:
add_filter(‘single_template’, create_function(
‘$the_template’,
‘foreach( (array) get_the_category() as $cat ) {
if ( file_exists(TEMPLATEPATH . “/single-{$cat->slug}.php”) )
return TEMPLATEPATH . “/single-{$cat->slug}.php”; }
return $the_template;’ )
);
and naming my second single.php with the slug name, in my case single-portfolio.php. But it is not exactly what I hoped to achieve. I need all my categories to use the new template I created. Can I do that or I have to create a template for each category? Thank you very much!