Skip Navigation

[Resolved] Display a CPT with different layouts based on conditions

This support ticket is created 7 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by John Johansen 7 years ago.

Assisted by: Luo Yang.

Author
Posts
#596585

Tell us what you are trying to do?
Display various CPT content based on or more conditions.
Generally, I need to know the preferred methods to display a CPT entry in various ways based on a condition (e.g. the user role or user type), preferably using the features of Layouts plugin.
I can create a CPT template using Layouts, and use the Visual Editor to insert sections of code controlled by conditions.
However, I'm not sure whether that technique allows the use of the other main Layout features within the code sections.
Is there any documentation that you are following?
Layouts
Is there a similar example that we can see?
Not examples, but earlier tickets that are similar but don't provide what I need to exploit the capabilities of the Layouts plugin that are not available in content templates.
1) https://toolset.com/forums/topic/multiple-product-view-templates/
2) https://toolset.com/forums/topic/multiple-templates-per-role-for-same-custom-post-type/
What is the link to your site?
Not applicable.

#596652

Dear John,

It needs custom codes, you can try with the Layouts filter hook "get_layout_id_for_render" to setup a PHP function, in this PHP function check if the condition is satisfied (e.g. the user role or user type), then return another specific layout ID, see similar thread here:
https://toolset.com/forums/topic/assign-layout-to-a-specific-archive/#post-411299

#596852

Luo:
Thanks for your quick response.
I think this is a very good start. I have reviewed the other tickets, and I believe they are very similar to my problem/solution.
I will do some testing today with the sample code and let you know how whether it resolves my issue.
JJ

#597024

I have developed a more generic function to use with "get_layout_id_for_render", and it works well. So, that's good.

I wonder why the use of this technique is not more widely used and why there is not (apparently) an example in the documentation of how to apply it to solve the problem that I have seen in at least three (3) different support tickets.

In my opinion, the ability to display a CPT entry using any one of a number of related layouts based on a set of independent conditions would significantly extend the flexibility of the basic Layout plugin functionality.