Skip Navigation

[Resolved] Multiple layouts for single CPT depending on url?

This support ticket is created 7 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
- 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 Luo Yang 7 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#539894

So I have a single CPT called Sponsored Artist. It has some fields like performer name, social media profile url, referral coupon code, etc.

This CPT needs to be viewed 2 different ways:
#1) A public profile page
#2) A hidden coupon referral page

#1 has an obvious solution, simply make a Layout for that CPT. Then it's accessible at: /sponsored-artist/the-artist-name. I've gotten that far.

For #2 I want to make an additional Layout that you access via a specific url. For instance /referral/the-artist-name. It would still have access to the same CPT and the same fields, but display them in a different way.

Could someone point me to the relevant section of the documentation for something like this? Thanks!

#539972

Dear Jordan,

I suggest you try this:
1) Create a page "referral" and design it with the additional Layout
2) In this page display a view, which is filter by URL parameter "the-artist-name"
https://toolset.com/documentation/user-guides/passing-arguments-to-views/
section "Controlling the filter with URL arguments"
3) in the URL "/sponsored-artist/the-artist-name", display a link to the page "referral", and pass URL parameter "the-artist-name" to the target page.

#540263

Ok, I have been tinkering with this but have not achieved the desired result.

* I created a Page /referral, and used Content Layout Editor to create a Layout for it.

* In this Layout I inserted shortcodes to show the following custom fields from the Sponsored Artist CPT:
[types field='artist-name'][/types]
[types field='coupon-code'][/types]

* I think I actually want to pass the instance of Sponsored Artist to the referral page by post slug (eg. /referral?some-artist, /referral?another-artist, /referral?yet-another-artist). So the /referral page would retrieve the 'artist-name' and 'coupon-code' for the particular Sponsored Artist instance who's post slug is given in the URL parameter.

* I tried to create a View for this using the "Controlling the filter with URL arguments" but the example in the documentation does not seem to apply to me. In that example, the URL parameter retrieves all instances of a CPT where a custom field equals a particular value. I'm trying to retrieve one specific instance of a CPT based on which post-slug is passed as a URL argument.

How do I use a View to retrieve a specific instance of Sponsored Artist based on it's post-slug being passed as a URL variable?

Assuming I can do the above, how do I connect that View to the referral page's Layout?

Thank you! 🙂

#540364

Q1) How do I use a View to retrieve a specific instance of Sponsored Artist based on it's post-slug being passed as a URL variable?
I suggest you pass the value of post ID as URL parameter, and filter the view by post ID, see our document:
Filtering Views Query by Post ID
https://toolset.com/documentation/user-guides/filtering-views-query-by-post-id/

Q2) how do I connect that View to the referral page's Layout?
As I mentioned above,
https://toolset.com/forums/topic/multiple-layouts-for-single-cpt-depending-on-url/#post-539972
step 1) Create a page "referral" and design it with the additional Layout
and in this page display that view