How to change single post template in WordPress based on category

How to change single post template in WordPress based on category and Want to figure out a way so you can target specific posts by specific categories in wordpress? Here you are. 

How to change single post template in WordPress based on category

Just open your wordpress theme editor and add this filter to your functions.php and name your template file to match the category slug: single-[cat slug].php i.e Custom Single Template for the posts in Fashion category would turn out to be single-fashion.php.

If you’re using a child theme, replace TEMPLATEPATH with STYLESHEETPATH

//Gets post cat slug and looks for single-[cat slug].php and applies it
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;' )
);

The Cavalier USA

Type: Website Designing, Website Development, SEO Campaign, Social Marketing, Social Presence, Link Building, Development & Website Content Management

Services Provided :

  • New Design
  • HTML/CSS
  • Javascript
  • Content Management System (WordPress CMS)
  • Advance Photo Gallery
  • Social Featured Footer
  • Customized forms
  • jQuery Transitions
  • Dynamic Contact Form (Interacts you direct to your Email inbox)
  • Social Marketing at Facebook, Twitter & YouTube
  • Keyword SEO Research.

Website: http://www.cavalierusa.com/

Completion Date : July, 2012

Mimi Productions

Type: Website Designing, Website Development, SEO Campaign, Social Marketing, Social Presence, Link Building, Development & Website Content Management

Services Provided :

  • New Design
  • HTML/CSS
  • Javascript
  • Content Management System (WordPress CMS)
  • Advance Photo Gallery
  • Social Featured Footer
  • Customized forms
  • jQuery Transitions
  • Dynamic Contact Form (Interacts you direct to your Email inbox)
  • Social Marketing at Facebook, Twitter & YouTube
  • Keyword SEO Research.

Website: http://www.mimiproduction.com/

Completion Date : June, 2012

iWed Productions

Type: Website Designing, Website Development, SEO Campaign, Social Marketing, Social Presence, Link Building, Development & Website Content Management

Services Provided :

  • New Design
  • HTML/CSS
  • Javascript
  • Content Management System (WordPress CMS)
  • Advance Photo Gallery
  • Social Featured Footer
  • Customized forms
  • jQuery Transitions
  • Dynamic Contact Form (Interacts you direct to your Email inbox)
  • Social Marketing at Facebook, Twitter & YouTube
  • Keyword SEO Research.

Website: http://www.iwedproduction.com/

Completion Date : February, 2012

CG Ramp

Type: Website Designing, Website Development, SEO Campaign, Social Marketing, Social Presence, Link Building, Development & Website Content Management

Services Provided :

  • New Design
  • HTML/CSS
  • Javascript
  • Content Management System (WordPress CMS)
  • Advance Photo Gallery
  • Social Featured Footer
  • Customized forms
  • jQuery Transitions
  • Dynamic Contact Form (Interacts you direct to your Email inbox)
  • Social Marketing at Facebook, Twitter & YouTube
  • Keyword SEO Research.

Website: http://www.forum.cgramp.com/

Completion Date : January, 2012