asign post template to posts in specific category? (automatically)

[ad_1]

I’m looking for a way to automatically apply a post-type-template to all the posts in a specific category, but I can’t find a workaround.

the closest I found is the category-slug.php [https://codex.wordpress.org/Category\_Templates]) …but I’m using the new [twenty-twenty-three]) theme and it seems to not use those files 🙁

any ideas?

[ad_2]
1 Comment
  1. Category-slug is for the archive page of the category, not the individual posts within that category.

    Interested to see what others recommend here. My gut reaction is to use conditionals in your single-post-type template to adjust the template when the post uses your category.

    <?php if(in_category(‘special’)) { ?>

    Your special template here

    <?php } else { ?>

    Default template here

    <?php } ?>

    Or if you really want separate files for each template, you could add something like this to your single template:

    <?php $post = $wp_query->post;

    if ( in_category( ‘special’ ) ) {

    include( TEMPLATEPATH.’/single-special-cat.php’ );

    } else {

    include( TEMPLATEPATH.’/single-generic.php’ );

    } ?>

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer