-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch-events.js
29 lines (25 loc) · 1.04 KB
/
fetch-events.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
jQuery(document).ready(function($) {
$.get('/wp-json/tribe/events/v1/events', function(data) {
var eventsHtml = '';
data.events.forEach(function(event) {
eventsHtml += '<div class="event">';
eventsHtml += '<p><a class="event-date">' + formatDate(event.start_date);
var startDate = event.start_date.split(' ')[0];
var endDate = event.end_date.split(' ')[0];
if (endDate && endDate !== startDate) {
eventsHtml += ' - ' + formatDate(event.end_date);
}
eventsHtml += '</a> <a class="event-title">' + event.title + '</a>'
eventsHtml += '</p>';
eventsHtml += '</div>';
});
$('.events-container').html(eventsHtml);
});
// Format date as "DD. MMM"
function formatDate(dateStr) {
var date = new Date(dateStr);
var day = String(date.getDate()).padStart(2, '0');
var month = date.toLocaleString('en-US', { month: 'short' });
return `${day}. ${month}`;
}
});