Hello, some times, I would like to display a view title with a link and posts count linking to post view on an index page, I know I can use [wpv-items-count] to show the post count found. but if so, I have to create tow view, one for showing the posts list, another one for showing posts count, and then put it on the index page.
Can I have a way to reuse the same view and modify some parameter to achieve that? Such as the example below
My published post 15------------------------- the view link with the item count
point this link to the my published post.
I consider this is a very common request, but I don't know why I can not find a answer in the forum.
Thank you so much!
Hi Jeffrey,
Thank you for contacting us and I'll be happy to assist.
To generate two different outputs from a single view, you can use an attribute value, passed through the view's shortcode.
( https://toolset.com/documentation/user-guides/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes )
You'll first create a view with a full output ( i.e. posts list ). Once it is ready, you can split the contents of the "Loop Editor" section into two conditional blocks.
( ref: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/ )
1. The first block will only show when "version" attribute in the view's shortcode will be set with the value "short".
[wpv-conditional if="( '[wpv-attribute name="version"]' eq 'short' )"]
<p>The count of posts is: [wpv-items-count].</p>
[/wpv-conditional]
2. Right below the first block, the second block will show when "version" attribute in the view's shortcode will not be set with the value "short".
[wpv-conditional if="( '[wpv-attribute name="version"]' ne 'short' )"]
[wpv-layout-start]
......
[wpv-layout-end]
[/wpv-conditional]
Please note how the whole content of this "Loop Editor" section ( starting from [wpv-layout-start] to [wpv-layout-end] ) is nested/wrapped inside this second conditional block.
As a result, when you'll need the full output of the view, you'll use the regular shortcode:
[wpv-view name="slug-of-the-view"]
And when you'd like to show the short version, you'll include a shortcode attribute version="short":
[wpv-view name="slug-of-the-view" version="short"]
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
My issue is resolved now. Thank you!