Set fixed post template for certain categories

Posted in: Newspaper
Post count: 101

hello, for our culture website we are building upon the newspaper theme and would like to do the following.

Certain types of posts, most importanly the posts in categories: live, camera eye and interview, have a large header image as set in the post template style as template number 6.
For instance see here: http://v2.enola.be/2018/03/28/bcuc/.

We would like to have that for these specific categories the template is always set as number 6.

Other posts in the categories film review, album review, don’t have large images attached and we don’t want the large header image as in template number 6 (it gets pretty ugly very fast), but for instance post template style nr. 12, which is missing the header image.
For instance see here: http://v2.enola.be/2018/02/27/us-girls-in-a-poem-unlimited/

For these posts in these categories we would like to see a fixed post template number 12.

So, instead of having to select it for each post with different category we would like to do it automatically, eliminating errors since we have quite a lot of users uploading content.

Is there a way to do this, for instance creating seperate single_template_6.php and loop-single-6.php files with a category slug, or won’t it work that way ?

kind regards for your insights on this.

Post count: 22421

Hello,

Sorry but you cannot set post styles per each category for the moment. The post styles can only be set globally or individually.

Thank you!

Post count: 101

That’s a bummer… Any chance it can be included in the next update ?
Would be really helpful.

I tried using this method but it breaks all post templates

/*
* Define a constant path to our single template folder
*/
define(SINGLE_PATH, TEMPLATEPATH . '/single');

/**
* Filter the single_template with our custom function
*/
add_filter('single_template', 'my_single_template');

/**
* Single template function which will choose our template
*/
function my_single_template($single) {
global $wp_query, $post;

/**
* Checks for single template by category
* Check by category slug and ID
*/
foreach((array)get_the_category() as $cat) :

if(file_exists(SINGLE_PATH . '/single-cat-' . $cat->slug . '.php'))
return SINGLE_PATH . '/single-cat-' . $cat->slug . '.php';

elseif(file_exists(SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php'))
return SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php';

endforeach;
}

Post count: 101

Is there a request page/address to ask for this feature or does it suffice that you know about it 🙂

Post count: 15

I’m dealing with same problem here. :\

Post count: 22421

Hello,

For the moment this is not part of our future plans. If this request becomes more popular, we will consider implementing such a feature into our theme. We have lots of requests and have to prioritize based on popularity.
I;m not sure this solution will still work but you can give this a shot:

https://forum.tagdiv.com/topic/different-post-template-for-one-category/

Thanks.

Post count: 15

Hi guys,

Many thanks for having gave us a light. We’re about to make it after following these tips provided. Once it done We’ll share here.

Thank you all.

Viewing 7 posts - 1 through 7 (of 7 total)
The forum ‘Newspaper’ is closed to new topics and replies.