Skip Navigation

[Resolved] How to display different content template per category or post or product

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to display different content template per category or post or product

Solution:
Toolset offers the hook: wpv_filter_force_template that you can use to change the content template on fly.

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/content-template-exceptions/#post-1966265

Relevant Documentation:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template

This support ticket is created 4 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by Matthew 4 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#1966071

Tell us what you are trying to do?
I'm currently using a content template for all products on my website. I want to create a NEW content template that is used on only one single product or product category, and specify that the existing content template NOT be used for that one product category.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?
hidden link

#1966265

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Toolset offers the hook: wpv_filter_force_template
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template

Which you can use to override the content template based on specific conditions.

For example:

add_filter( 'wpv_filter_force_template', 'func_assign_ct_dynamically', 99, 3 );
  function func_assign_ct_dynamically( $template_selected, $post_id, $kind ) {
     
    if($color=='red') {   // assuming $color value coming from taxonomy 
        $template_selected = 777; 
     } else if($post_id==2) {
        $template_selected = 999;  
    }
    return $template_selected;
}

Where:
- Please feel free to adjust the code as required
- replace 777 and 999 with the content template IDs

#1967461

Hi Minesh

thx for your reply. I decided to go another route. Since I'm already using Beaver Builder and Beaver Themer, I decided to create a special singular template just for this one product. It was a bit easier.

thx!
- Matt