Support » Fixing WordPress » single-bars.php Not Being Used

  • Resolved Gemfruit


    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.

Viewing 1 replies (of 1 total)
  • 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;' )
Viewing 1 replies (of 1 total)
  • The topic ‘single-bars.php Not Being Used’ is closed to new replies.