Use STYLESHEETPATH
instead of TEMPLATEPATH
. You’ll find the definitions in wp-includes/default-constants.php
file. Please have look. So your code block will be like below-
//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(STYLESHEETPATH . "/single-{$cat->slug}.php") )
return STYLESHEETPATH . "/single-{$cat->slug}.php";
}
return $the_template;'
)
);
Hope that helps you.
Related Posts:
- WordPress Multisite – global categories
- Get posts from sites in Multisite?
- How do I get the category URL from get_the_category?
- Multisite – Protect categories from deletion?
- Category page doesn’t use category.php, instead it redirects to homepage
- 5 blogs on one WordPress site
- Multisite blog converting categories to subdomains
- Adding categories to all blogs at once
- Create single.php for specific category by category id
- WordPress MU 2.9.2 to 3.0.5 changes to category.php
- How to make category RSS feeds show full content
- How to get category id in single.php wordpress?
- Multi-site or categories?
- Multisite – create a category in specific site
- WordPress Multisite – global categories
- Default category link for a custom category is a broken link
- in_category() works in single.php but not in page.php?
- Archives for each category on WP Multisite
- previous/next_post_link in the same sub-category?
- Send to different single pages by category when multiple categories exist
- How do I share categories across selected sites in a Multisite setup
- get_categories() returns “Uncategorised”
- How to make the link to the category for a post go to corresponding page number in archive?
- wordpress multisite… collect all posts on main blog – exclude category?
- Can Categories be used to hack a Multisite-like setup w/ a single MySql db?
- Single.php Category Post Count
- Problems with my conditionals in single.php by category
- Get next post in same category not working WP 4.7.4
- Simple way to style posts of a single category differently in the loop and in single
- How to Sync Menu, Widgets and other masters from Main Website to its Sub Site
- How to get nav to show current_page_parent class when on regular post (not blog), differentiated by category
- How can I check which archive has referred the single? [closed]
- Displaying links to all posts of the same category on the post page
- Categories show 404 error on multisite installation
- Global navigation in multisite: problem with categories
- Duplicate new categories across multisite network
- Ignore the Ad on Specific Categories
- custom wp_list_categories in single.php
- get_the_category return empty inside loop
- loop in single.php of the same category
- Display Some text in some specific category not all category
- When category name and title are the same … WP will select archive.php instead of single.php
- global categories – Share specific categories in wordpress multisite
- Limit Category/Tag Dropdown To blog_id in Multisite Install With Global Categories/Tags
- Code to display category-specific single.php is overriding normal single.php, too
- A search box for all sites – Multisite
- Display Referring Category on single post?
- How to create default categories in new installs?
- Multiple parent categories
- Modify / Rewrite single template url structure
- How to populate a WordPress install with a lot of categories, quickly?
- How to structure Multisite sites into categories?
- How do I get a single page navigation depending on the previous page?
- Control term order on a per-post basis
- Display all posts from all categories with pagination
- Changing Top Level Items into Radio Buttons in the Categories Meta Box?
- How to create a widgetized sidebar for every category dynamically?
- Display the deepest child category from Category X (in loop)
- When using get_categories or similar, is it possible to filter results that contain certain Tags as well?
- Select category in custom query
- Removed slug from CPT, now How/where do I hook the filter to the taxonomy term archive pages link?
- How to control template resolution if both Author and Category filter in place?
- Resolved – category-slug.php not working after wordpress migration
- How to retain the values from dropdown category lists after wrong form submission?
- Single_cat_title() print the title before text
- Sort posts by post_type in category.php template
- Add Post Screen Keep Category structure
- editing fonts of category links from the_category() funtion
- Style wp_list_categories
- Checking for two categories in query_posts
- Show category to visitors in different name or different language without changing basic category
- How to get latest posts from each category in regular order
- Pagination for ajax category filter
- Get posts from specific taxonomy term
- limit a list of tags to one category [closed]
- How many categories can WordPress handle before performance suffers?
- WordPress Drop down category as array for using in page builder
- Get sort order of product categories
- How to pull a list of posts in a category while exluding posts in subcategories of the category
- Display posts of certain categories to specific user roles
- Display Related Posts by “Category” “by Author”
- Change post title if post has specific category
- How set all posts in wordpress in one category
- custom query for both category and pages using global $wpdb;
- url for posts for a date within a category
- Autolinking keywords in text with tags
- WP E-Commerce creating categories programmaticaly [closed]
- WordPress PageNavi Plugin not working in category.php
- Different post slug based on archive
- Show single post child category from a determined parent
- How do I get conditional sidebars for specific category archives and posts
- Post does not show category wish just show latest post
- Woocommerce Category Sort Dropdown
- Is there a way to ‘archive’ inactive categories?
- Display one post on category.php: Wrong featured image
- Taxonomy for custom post type not found
- How can I get this code to only output one link?
- How to get Woocomerce categories count
- show posts from some category and sort by advance custom field
- CPT Custom post type Tags & Categories not showing for ‘Editor’ user in editor