Skip Navigation

[Resolved] Display my event calendar monthly

This support ticket is created 6 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 6 years ago.

Assisted by: Nigel.

Author
Posts
#1154561

Tell us what you are trying to do?
I want to show my CPT in a list sorted monthly, I thought I could accomplish it in an nested view, but do not solve it myself.
I have custom date field and thought I could use that field to sort the list.

Is there any documentation that you are following?
Have not found anything useful

Is there a similar example that we can see?
No
What is the link to your site?
hidden link
Have only one event now. 🙂

#1154750

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You mean you want to output something like

July
summer post
another post
one more
August
hot post
holiday post
September
back to school post
hello autumn post

?

You can order the posts by date easily enough, but the way the results of a query are iterated over there is no way to group them, or recognise when something has changed (e.g. the month coming from a date field) to add a separator.

One solution would be to create a custom shortcode where the month divider would go which recorded the month as a static variable in PHP to enable you to compare the month from the date field of the current post to that of the previous iteration, and if it had changed, output the month divider.

But a simpler solution occurs to me, using CSS, although as I try to test it I think it would only be viable if you were dealing with a single year and not repetitions of months.

Output a month divider for every iteration. (You can output the date field as a month.) Be sure to wrap it in a div, and add a dynamic class to the div such as "month-Dec", "month-Jan" etc.

How?

By dynamically generating the class name with the types shortcode for the date field, like so:

<div class="month-[types field='publication' style='text' format='M'][/types]">
  [types field='publication' style='text' format='F'][/types]
</div>

(See https://codex.wordpress.org/Formatting_Date_and_Time for the codes for formatting dates.)

That results in something like this on the front-end:

<div class="month-Mar">
  March
</div>

You can then use CSS to hide all such month dividers, and then add style rules using :first-of-type to re-enable the first of each divider, like so:

div[class*='month'] {
  display: none;
}
div[class='month-Jan']:first-of-type {
  display: block;
}
div[class='month-Feb']:first-of-type {
  display: block;
}
etc...

I thought it might be possible to combine the wildcard selector and :first-of-type but it doesn't appear to work, but perhaps you can think of a CSS selector that would.