Support,
Please see attached image. The output on the right circled in red is produced from the current view and its content template which is assigned to all the posts. The image inserted on the left is an example of what I would like to incorporate into the mix. It's a post with an image to an external link. Is there a way to modify the current view to have two views; either conditionally or a separate or view?
Note this is a screenshot of the view with the image circled in blue laid on top to achieve my goal.
Thanks,
Charles
Sorry, I can't see an attachment. Can you add the image to your next reply?
Image too large to attach. Can be viewed here hidden link
Thanks!
Okay I see now thank you. It looks like you want some results in a View to be displayed using one template, and other results in the same View to be displayed using another template. This can be accomplished in different ways depending on how you determine which items receive which template. Have you reviewed this documentation?
https://toolset.com/documentation/user-guides/digging-into-view-outputs/
Check the section "Loop parameters & wpv-item : wrap, pad, pad-last, index" for specific information about how to use wpv-item and index to specify different output for different elements of a loop, in a repeating pattern.
Another option is to use conditional HTML in your View's Loop. For example, if you want to apply Template #2 to all results having a custom field value of "2", but apply Template #1 to all other results, you could do something like this:
<wpv-loop>
[wpv-conditional if="( $(wpcf-fieldslug) eq '2' )"]
[wpv-post-body view_template="CT #2"]
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-fieldslug) ne '2' )"]
[wpv-post-body view_template="CT #1"]
[/wpv-conditional]
</wpv-loop>
Once you have the markup in place, you can use the CSS editor in the View's Loop panel to add any necessary CSS.
*edit - updated to fix code formatting
Worked like a charm. I used the select field and coded like this:
<wpv-loop>
<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 grid-item">
[wpv-conditional if="( $(type-of-post) eq '1' )"]
[wpv-post-body view_template="Loop Item in Main View"]
[/wpv-conditional]
[wpv-conditional if="( $(type-of-post) ne '1' )"]
[wpv-post-body view_template="main-view-ad"]
[/wpv-conditional]
</div>
</wpv-loop>
Is it possible to have a 3rd and 4th template if desired?
Thanks,
Charles
Yes, that's possible. In your View's Loop, you will copy and paste a conditional code block for each template. All the conditionals should test if the type-of-post value is equal to something, since the options are no longer only 1 or 2.
[wpv-conditional if="( $(type-of-post) eq '1' )"]
[wpv-post-body view_template="template-1-slug"]
[/wpv-conditional]
[wpv-conditional if="( $(type-of-post) eq '2' )"]
[wpv-post-body view_template="template-2-slug"]
[/wpv-conditional]
[wpv-conditional if="( $(type-of-post) eq '3' )"]
[wpv-post-body view_template="template-3-slug"]
[/wpv-conditional]
We have documentation for conditional HTML here: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/