Skip Navigation

[Resolved] various template for single page

This support ticket is created 3 years 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)

Author
Posts
#2010535

In a website (still in construction) I have one custom Port Type: “Cases”.
I am looking for a way to apply 2 different Content Templates to Case posts.
One is to display all fields on one page.
The other is to display only a few fields in a different lay-out. This page will serve as a kind of “certificate” and will be printable on paper or as pdf.

1 Here I found that multiple content templates for one CPT is not possible,
https://toolset.com/forums/topic/multiple-templates-for-custom-post-type/

2 But here it seems possible:
https://toolset.com/forums/topic/showing-all-posts-of-a-custom-post-type-with-different-content-templates-on-one/

3 In this thread I found another suggestion:
https://toolset.com/forums/topic/link-to-multiple-single-pagecontent-template/,
but the conclusion in the end of the thread said Ok so unfortunately its not possible as the content template need to be assigned in the post edit page so it wouldn't be abe to dynamically render a content template for a post.

Do you thing solution 2 is worth trying?
Would it be possible to generate the page with the “certificate” template by clicking a button on the original single page view?

Below is an impression of how the 2 pages should look.

Single template 1 for Case

Title
Description
Field 1
Field 2
Field 3

Field 43
Taxonomy terms
Etc.

Button: click here to view (or download) your certificate

Single template for 2 Case (=certificate)

Title
Description
Field 1
Field 2
Field 3

#2010777

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Yes, you can either use the [wpv-conditional] shortcode to display the content template conditionally:
=> https://toolset.com/documentation/legacy-features/views-plugin/checking-fields-and-other-elements-for-emptynon-empty-values/

OR

You should create different content templates as required and then you can switch the content template based on your required condition. You can use the view's filter hook: wpv_filter_force_template
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template

For example:

add_filter( 'wpv_filter_force_template', 'prefix_fixed_content_for_visitors', 99, 3 );
   
function prefix_fixed_content_for_visitors( $template_selected, $id, $kind ) {
    if ( !is_user_logged_in() && $id == 999 ) { 
        $template_selected = 1; 
    } else  if ( !is_user_logged_in() && $id == 888 ) { 
        $template_selected = 2; 
    }  if ( !is_user_logged_in() && $id == 777 ) { 
        $template_selected = 3; 
    }
    return $template_selected;
}

Where:
- $id is the post ID and you have to assign the original content template ID instead of 1,2 and 3. You can adjust the code as per your requirement.

#2012109

Thank you Minesh.
I continued with your first suggestion together with this support thread: https://toolset.com/forums/topic/showing-all-posts-of-a-custom-post-type-with-different-content-templates-on-one/

I added the [wpv-conditional] shortcode to display the text "Download certificate" in the content template conditionally: if the select field "Download certificate" is checked / has the value of "1". This works.

Now I want the text "Download certificate" to be a button / link to a post or page with the content template for that specific case, showing only a few of the fields and in a different lay-out.

I am using the block editor.
Do I have to create a second content template for the CPT "Cases"?
How do I assign that template to the CPT "Cases" as it seems only possible to assign 1 content template to 1 CPT?
How do I auto-generate the link to the post or page for that specific case?

I hope you can help me further.

#2012977

Minesh
Supporter

Languages: English (English )

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

You should try to create another content template and add your desired fields there as per your requirement and do not assign this content template to any post type.

Then, you should link your content template with content template ID.

for example:

<em><u>hidden link</u></em>

Where:
- 9999 is the content template ID with different layout.

#2013489

Thank you, Minesh, I got this working.
Just one issue to resolve:
In my original content template I have a map that shows the location of the specific case.
I want this map to display on the certificate template as well. But the marker does not appear there, only an empty map without any marker.

#2013491

Minesh
Supporter

Languages: English (English )

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

Glad to know that solution I shared help you to resolve your issue.

We entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery. I'll split the ticket with your new question and you are welcome to mark this ticket resolved.

#2018097

My issue is resolved now. Thank you!

#2018191

I tried your solution.

Configuring the marker in the map's setting sections in the sidebar:
As this template is not assigned to any post type, I could not configure map's marker setting sections in the sidebar.

I resolved this by temporarily assigning the template for EOW passport Passport to CPT Cases.
Then I was able to adjust the marker settings.

After adjusting the marker settings I reassigned the Template for cases to CPT Cases.
And now the map + marker displays OK.
Case single: hidden link
Case EOW passport single: hidden link

My issue is resolved now. Thank you!

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