nikolaou,
When I understand you question correct then you want to use different templates based on the categories you’re using within your posts, correct?
If that’s the case, then you only need one template (single.php) and a combination of get_the_terms()
and get_template_part()
.
<?php
$categories = get_the_terms(get_the_ID(), 'slug');
if ( in_array('cat1', $categories) ) {
get_template_part('partials/single', '1');
} elseif ( in_array('cat2', $categories) ) {
get_template_part('partials/single', '2');
}
?>
You should place the code above within The Loop. The two template files are called single-1.php and single-2.php and stored within a folder called partials.
Sources:
Related Posts:
- How to get Images included in Post
- Use template of parent category for single post sub-categories
- How only display all post related to category
- Different template for posts of all subcategories of category
- Mark menu item as current-menu-item for category
- Category Template: Need to display different content on first page of archives
- Exclude category from
- Disable sticky option for specific categories
- How to create a template for Pages?
- How do I stop the loop from repeating in my category template?
- how to hide empty fields of post category description?
- Which hooks are essential for post templates?
- Display the first post’s comments of category in comments.php template
- how to style an individual page in a category [duplicate]
- Change from all posts to specific categories post on main page?
- excerpt in template for specific page
- Is there a block to print post link standalone in a block theme?
- Show category name in category.php when posts assigned to multiple categories
- Show posts assigned to multiple categories in current category page
- Blog page not working
- What is the filter or hook to add admin controls to posts on the front end?
- Different templates for different category tags
- Assign category to new post via URL
- Setting posts_per_page for taxonomy term template
- Stop users posting into category while still seeing contents of the category
- How to display the link (title) and thumbnail post?
- Underscores Theme Unit Testing – Catching Untitled Posts
- get_the_excerpt() is not working as expected – returns wrong text
- Category Page Template not Showing Posts
- display a random post thumbnail from a random category
- How do I retrieve then print the currently viewed sub categories?
- How to use format post in a pertinent way
- How to allow users to post only in certain category and hide elements from edit page?
- How can i limit the number of posts created per category?
- How to Restrict Previous & Next Post Link to Posts of Same Category?
- Pulling in post category and children within category
- WordPress custom Query for Posts in Category display posts multiple times
- Post categories to pages
- Switch to page template when using post permalink
- Get user categories with most posts in it
- Unable to restore from backup – how to obtain old blog posts?
- Post page to display specific category
- Get Posts Under Custom Taxonomy
- Get attachments for posts that belongs to a specific category
- Genesis + Ajax + Jquery | Failling to call action
- Prevent additional top level categories but allow more children
- Need help with category listing!
- Prepending %category% onto default posts fails
- List all categories with featured image from post?
- Get Page ID of blog homepage
- Categories list into registration form
- Send post id through ajax and get the post content back
- WP_Query: Mixing category__in and tag__in together
- If in_category not working for multiple single.php pages
- How can I setup a relationship using categories in WordPress?
- WordPress Multisite – Create Default Post and New Category On New Site Install
- how to show single post in a custom template
- Using ajax on editing a category edit page?
- Related posts by category not working right
- custom post template file not shown, instead all the time 404.php
- How to list recent posts in a wp nav menu?
- Set Default Category to Username
- Dynamic dependent Dropdown lists for categories, sub-categories and posts
- How can I hide tags on a child-category page, if that tag has not been used?
- date issue with category post retrival
- Listing Specific Categories from Current Post with Depth
- How to make multiple sections in home pulling posts category wise?
- Highlight static blog page link in header
- How to display two blog categories as separate sections on one page?
- How to create new post content templates for my users?
- How to make the first post in the loop be styled like a “new / featured” post?
- How to Mysql select a list of posts with meta_values AND all relevant categories?
- Redirect to another page using contact form 7? [closed]
- Display post category in foreach loop
- Single.php – Get Current Parent Category
- get_the_category listing in hierarchial order
- How do I do a page break?
- Is it possible to add/tick a category to a post when it is created?
- Excluding posts not working
- Hide posts belongs to few categories in homepage
- why does wordpress ignore the post args?
- post category in wp_insert_post
- Limit the number of posts a category can have – newest post goes in, oldest one drops out, possible? plugin?
- posts not showing on index.php
- Block editors annoying warnings
- How to get subcategories from category slug?
- Remove current category from post but display all others
- How show categories in admin and get that selected to show posts in index
- Showing categories and subcategories with posts
- Change default category when I publish a post
- What does WordPress do if I save a post without content/title? [duplicate]
- store posts_id of category into a varable?
- Hide a specific post from a page template
- How to display two random-post sections that are each under their own category
- How can you display all sibling categories to a post?
- How to add a class to edit_post_link?
- Loop doesn’t exclude the specified category in home page
- Tell WP to use a specific template file in posts
- Display posts of specific category term
- Widget that shows categories with posts numbers