I have thought about this issue and tried to visualise it the best I can for myself but I can't figure it out. Apologies if the answer is very simple, I just can't get there myself!
I am aware that you can set a View to query multiple different CPTs and then design the output within the Loop Editor. I wish to be able to do this but to use a different Content Template for each returned result, dependant on the CPT. Is this possible and how would I achieve this?
For example; for every result that is CPT of "Author" I would like to use an "Author" Content Template designed just for this CPT and for every result that is CPT of "Book" then I would like to use a "Book" Content Template.
I hope this makes sense. Let me know if there is anything else you need.
I was looking for some sort of conditional to test the CPT type but I couldn't find anything like this.
Hi Ben,
Thanks for asking! I'd be happy to help.
To show different content templates for the different CPTs returned through a single view, you can use "wpv-post-type" type shortcode, which returns the current post's post type:
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-153408
This shortcode can be nested inside a conditional shortcode, to show different content templates, accordingly:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
For example, in your view's main content template you can add:
[wpv-conditional if="( '[wpv-post-type]' eq 'author' )"]
[wpv-post-body view_template="ct-for-author"]
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-type]' eq 'book' )"]
[wpv-post-body view_template="ct-for-book"]
[/wpv-conditional]
Feel free to replace "author" and "book" with your actual CPT slugs and "ct-for-author" and "ct-for-book", with actual content template slugs.
I hope this helps.
regards,
Waqar
Thank you for your reply Waqar.
This is perfect and exactly what I wanted to do!