[resolved] single-bars.php Not Being Used (2 posts)

  1. Gemfruit
    Posted 2 years ago #

    I've created a single-bars.php file, to change a few specifics for any post in my "bars" category. I'm 99% sure that's how the WordPress hierarchy system works, as I did the same with a plugin by doing single-ai1ec_event.php, with my desired effect working. For whatever reason, my single-bars.php is not being used, and single.php is.

    Two questions, any ideas why this is? (I'm 100% the slug is correct)
    Side question, what's the difference between single and archive, as I find the descriptions confusing.

  2. Gemfruit
    Posted 2 years ago #

    I solved the issue, my understanding wasn't 100% correct.

    WordPress does NOT have native support for using single-type, where type is the category type. The reason single-ai1ec_event.php worked, was because that plugin specifically adds a custom post type.

    To add a custom post type for all of your category types, add the following to functions.php. Change TEMPLATEPATH to STYLESHEETPATH if you're using a child theme.

    //Gets post cat slug and looks for single-[cat slug].php and applies it
    add_filter('single_template', create_function(
    	'foreach( (array) get_the_category() as $cat ) {
    		if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") )
    		return TEMPLATEPATH . "/single-{$cat->slug}.php"; }
    	return $the_template;' )

Topic Closed

This topic has been closed to new replies.

About this Topic