Skip Navigation

[Gelöst] List of posts grouped by Year and Month.

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

How could I create a Loop with posts grouped by Year and Month?


If you require a adequate posts count as well to this YEAR/MONTH outputs, you can follow these steps as well:

Relevant Documentation:

This support ticket is created vor 5 Jahre, 8 Monate. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 Antworten, has 2 Stimmen.

Last updated by ashleighP vor 5 Jahre, 8 Monate.

Assigned support staff: Beda.

Screen Shot 2018-01-19 at 7.55.03 PM.png

Tell us what you are trying to do? I want to create a list that shows the years for which there are existing blog posts and then a sub-list with the months for which there are existing blog posts, which links to each date-related archive page.

I've done this before with no problem for things like product categories + subcategories, but I can't find a way to list out the archive pages based on date. I can customize those archive pages using views, but not use a shortcode to link to them?

Is there any documentation that you are following? Views query by date; custom search; shortcodes for archives

Is there a similar example that we can see? Screenshot attached

What is the link to your site? hidden link


Here is as tech bulletin entry that explains how to do exactly what you need.

I tested this and it successfully groups Years (Output only once each) and Months, plus posts.

Front here it should be easy to group them in Additional HTML like accordions or link to other pages.

For reference, I will consult the code provided in the above bulletin with the developer as it seems wrong to me, and I needed to adjust the shortcodes a little:

    [heading condition="year" value="[wpv-post-date format='Y']"]
      <h4>[wpv-post-date format="Y" id="[wpv-post-id]"]</h4>
    [heading condition="month" value="[wpv-post-date format='F']"]
      <h5>[wpv-post-date format="F" id="[wpv-post-id]"]</h5>

I added the Post ID

The rest worked as is.

Please let me know if this helps-

Screen Shot 2018-01-23 at 5.18.41 PM.png

I found this tutorial while I was searching support, but it doesn't do quite what I'm hoping for.

Because it's not actually applying any filter to the query result, the [wpv-items-count] shortcode doesn't return the number of posts in that month or year, it returns the total number of posts. (see screenshot)


I understand. This is not possible with this ShortCode.

I can customize those archive pages using views, but not use a shortcode to link to them?

Right, we do not have a ShortCode linking to either the Year archives, Month archives or Day archives.
But that should not be needed, you can craft a Custom Link similar to this:

<a href="[wpv-bloginfo show='url']/[wpv-post-date format='Y']">[wpv-post-date format="Y"]</a>

The post count thou is another issue.
Here we would need to alter each query but that is not possible within the Query Filters of the very View, these would affect all posts.
So you would need a second, nested View, with a Query that takes the date from a ShortCode attribute and returns only the Post Count.
Then, add the [wpv-items-count] above the Loop of this new View.
After, insert the View in the Loop of your first View, as this:

[wpv-view name="post-count-per-year" year="[wpv-post-date format='Y']"]

Unfortunately the feature you require is not inbuilt natively in Toolset, but it is achievable with above steps.

I can suggest this with a "adequate" amount of data. If you plan to have 10s of thousands of posts, I suggest to not use Toolset Views for this, as nesting the Views can result in a high load with the increasing amount of posts.
I speak of large amounts.

Please let me know if with these steps you are able to achieve the result you wish?


Yes, this works. Thank you!