Skip Navigation

[Resolved] Group views output exclusively by year

This thread is resolved. Here is a description of the problem and solution.

Problem:

Groups the results yearly in the archive page of grid layout mode.

Solution:

Here is an example:

https://toolset.com/forums/topic/group-views-output-exclusively-by-year/#post-2055013

Relevant Documentation:

https://toolset.com/2013/10/how-to-group-views-results-by-year-and-month/

This support ticket is created 4 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 2 replies, has 2 voices.

Last updated by jayesonE 4 years ago.

Assisted by: Luo Yang.

Author
Posts
#2054681

I need to group the views output by each year into rows of 4 videos without the rows filling in if the year does not have 4 items.
Here is the code I am using which creates the rows and condition for the year. As you can see in the link below items for 2020 have wrapped into the 2021 row because there is only one item for 2021.

hidden link

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<div class="container wpv-loop js-wpv-loop">
<wpv-loop wrap="4" pad="true">
[wpv-item index=1]
<div class="pt-3"><h2>[heading condition="year" value="[wpv-post-date format="Y"]"][wpv-post-date format="Y"][/heading]</h2></div>
<div class="row ">
<div class="col-md-3 px-3 py-3">[wpv-post-body view_template="loop-item-in-vimeo-videos"]</div>
[wpv-item index=other]
<div class="col-md-3 px-3 py-3">[wpv-post-body view_template="loop-item-in-vimeo-videos"]</div>
[wpv-item index=4]
<div class="col-md-3 px-3 py-3">[wpv-post-body view_template="loop-item-in-vimeo-videos"]</div>
</div>
[wpv-item index=pad]
<div class="col-md-3 px-3 py-3">pad</div>
[wpv-item index=pad-last]
<div class="col-md-3 px-3 py-3">pad-last</div>
</wpv-loop>[wpv-pager-archive-nav-links output="bootstrap" first_last_links="true"]
</div>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

#2055013

Hello,

I assume we are talking about the custom shortcode [heading] from below document:
https://toolset.com/2013/10/how-to-group-views-results-by-year-and-month/

Please try to modify the codes you mentioned above as below:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<div class="container wpv-loop js-wpv-loop">
    <div class="row ">
<wpv-loop>
[heading condition="year" value="[wpv-post-date format="Y"]"]
    </div><div class="pt-3"><h2>[wpv-post-date format="Y"]</h2></div><div class="row ">
[/heading]
<div class="col-md-3 px-3 py-3">[wpv-post-body view_template="loop-item-in-vimeo-videos"]</div>
</wpv-loop>[wpv-pager-archive-nav-links output="bootstrap" first_last_links="true"]
	</div>
</div>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

And test again

#2055511

My issue is resolved now. Thank you!