Skip Navigation

[Resolved] Multiple content templates for a custom post type

This support ticket is created 4 years, 4 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 4 replies, has 2 voices.

Last updated by Vane 4 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1425993

Hi,

I'd like to use different content templates (CT) for a custom post type (CPT) on their single page and on some Views which contain also their data.
For example, let's say the CPT is Book,
and I'd like to have and use
Title (H2), Content Body (Book description; full) and Image (large) on its single (details) page,
and in a View:
Title (as link; H4)), Content Body ( cut by words like 20 ) and Image (medium or thumbnail).

So I created the CT for Books as the first, but I can not define another CT for the Books View!
Theoretically it is possible to create multiple Views for these Books, having to have different CTs with different data.

So my Q1 is:
is there a way to use multiple CTs for a CPT? if not, do you have a workaround idea?

My Q2 is:
I prefer not to add also an Excerpt to every each Book, cutting manually the Body content.
AFAIK only Excerpts can be cut by words, but that would be great to be able to cut any multiline text that way.
So could you have also a workaround?

Thank you!

#1426023

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

So my Q1 is:
is there a way to use multiple CTs for a CPT? if not, do you have a workaround idea?
==>
Actually, at a time, you can only assign one content template to the content template you design to display the single post of your post type.

if you want to assign multiple contents templates, so for instance, lets say you have color taxonomy having red and green as terms and you want to display different content templates dynamically when you display post which have red term assigned and post where green term assigned, you can use the view's filter hook: wpv_filter_force_template

In such cases, you should create the different content templates and add your desired content to it and you can switch the content tempalte assignment dynamically:

For example:

add_filter( 'wpv_filter_force_template', 'func_assign_ct_dynamically', 99, 3 );
  function func_assign_ct_dynamically( $template_selected, $id, $kind ) {
 
      if($color=='red') {
        $template_selected = 777; 
     } else if($color=='green') {
        $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

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template

Note: I'll handle Q2 with the ticket I split.

#1426147

Hi Minesh,

thank you, but I don't want to display content or different content templates conditionally in this case.
The Conditional Block is used elsewhere and I find it very useful, but this case using that just would make the template unnecessarily complex, the generated code too big, etc.

Basically I didn't want to use multiple CTs by CPT, but I'm forced to do, because I prefer Block Editor over tweaking shortcodes and HTML (old Views Editor)

Also, in your examples pls. stay within my Books example: I want to display CPT CFs (custom fields) and not CTs (custom taxonomy), which work very differently in several cases.

-----------

Most of us Toolset users bought our license because we don't know PHP well enough or don't want to tweak PHP code.

I honestly dislike this concept, not being able to define multiple CTs by CPT.
This time I can set up one for eg. Books, which must be used on single CPT page and also in every each Views.
The one I would like would work this way:
having multiple CTs by CPT and being able to set one of them as single, not too complex! 🙂

I'm using Toolset for years and I sill don't understand what exactly is this product and what type of clients is it created for?!
I mean:
- is it a CPT, CT, CF, View etc. management tool or a page builder; is it created for the masses, the non-coder WP admins or the for the professional coders? It helps to minimize PHP, but what about javascript? Etc.
- In some cases it help us to solve complex tasks easily but in another cases it doesn't allow us to decide some very basic settings ( like using multiple CTs by CPT)
- it doesn't contain such basic features like advanced input fields like searchable multiselect:
hidden link
or
Country / City lists or Currency lists with standard, 3rd party data (eg. Google or OpenStreetMaps) which would really be a huge help!

-----------

So if I can't have multiple CT per CPT, I - and I think others - would like to use Block Editor to edit the content inside a View and I don' want to compulsorily use the sole CPT CT of that CPT.

So pls. Toolset remove either this restriction or the other!

Thank you

#1426287

Minesh
Supporter

Languages: English (English )

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

Also, in your examples pls. stay within my Books example: I want to display CPT CFs (custom fields) and not CTs (custom taxonomy), which work very differently in several cases.
===>
Ok - it was just a simple example to demonstrate "wpv_filter_force_template" hook usage.

I honestly dislike this concept, not being able to define multiple CTs by CPT.
===>
Theoretically, you can create as many templates you want to but only assign one template to display with your specific post type or post types, as you are allowed to assign the same template to multiple post types. Please check the following screenshot:
- hidden link

Please check the following Doc:
https://toolset.com/documentation/getting-started-with-toolset/create-templates-to-display-custom-posts/

I'm using Toolset for years and I sill don't understand what exactly is this product and what type of clients is it created for?!
I mean:
- is it a CPT, CT, CF, View etc. management tool or a page builder; is it created for the masses, the non-coder WP admins or the for the coders? It helps to minimize PHP, but what about javascript? Etc.
===>
As you acknowledge that you are using Toolset for years then you would know that Toolset is a package of different plugins where each plugins role is different where:

Toolset Types => Will help you to build the structure like (post types, custom field (post,term), taxonomies, post-relationship)
Toolset Views => To display and list content on frontend (simple list with pagination, sliders, custom search etc..etc)
Toolset Forms => To build frontend forms for post types, users and post-relationship forms
Toolset Maps => To display the maps on frontend and offers distance search
and many more....
Please check the following blog post:
=> https://toolset.com/2019/11/toolset-views-becoming-toolset-blocks/

- In some cases, it helps us to solve complex tasks easily but in another case, it doesn't allow us to decide some very basic settings ( like using multiple CTs by CPT)
===>
If you can clarify exactly where you stuck with views or displaying content template for a single post - then I will be able to guide you in the right direction.

- it doesn't contain such basic features like advanced input fields like searchable multiselect:
hidden link
or
Country / City lists or Currency lists with standard, 3rd party data (eg. Google or OpenStreetMaps) which would really be a huge help!
===>
As you may know Toolset block is still in early life and incremental stage. As you can see with the changelog, those blocks are currently available.
- https://toolset.com/es/download/toolset-blocks/#changelog

We do have plans to add additional lots of features that especially emphasize on the design/layout/responsiveness that will help the users to build the site effectively easy.

However - I encourage you to add feature request for your "advanced input fields" and "Country / City lists or Currency lists" suggestions - so our Devs can review:
=> https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

So if I can't have multiple CT per CPT, I - and I think others - would like to use Block Editor to edit the content inside a View and I don' want to compulsorily use the sole CPT CT of that CPT.
===>
Please check the following blog post where Dario Shared a few videos that might be helpful to you understand how you can design single template for post type, post type archive and views using blocks:
- https://toolset.com/2019/12/learn-how-to-build-templates-archives-and-views-with-blocks/

#1426353

qq

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.