anniegerway Posted November 21 Posted November 21 Site URL: https://mnbookarts.squarespace.com/category/adult-workshops Hello! Has anyone created a code to display a range of dates for a multi-day event on the date tag for events summary blocks? url: https://mnbookarts.squarespace.com/category/adult-workshops I would love this event to say "Dec 12-Dec 19". Image below.
tuanphan Posted November 25 Posted November 25 Hi, The url doesn't work. anniegerway 1 Email me if you have need any help (free, of course.). Answer within 24 hours. Or send to forum message Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)
anniegerway Posted November 26 Author Posted November 26 On 11/25/2024 at 5:01 AM, tuanphan said: Hi, The url doesn't work. ah apologies! I had the page disabled. It should work now. Thanks for looking into this!
tuanphan Posted November 28 Posted November 28 On 11/26/2024 at 9:43 PM, anniegerway said: ah apologies! I had the page disabled. It should work now. Thanks for looking into this! I think we can enable metadata date, then use code to move it over thumbnail, in current date position See screenshot, this in my site. If you want to try this, I can test some code on my site then give you code Email me if you have need any help (free, of course.). Answer within 24 hours. Or send to forum message Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)
anniegerway Posted December 2 Author Posted December 2 (edited) I think that would work! Let's try it! @tuanphan Edited December 2 by anniegerway
anniegerway Posted December 2 Author Posted December 2 It may be worth noting that the date tags on the actual events collection page do show a range. Wonder if the code can be pulled from that somehow???
anniegerway Posted December 3 Author Posted December 3 I've made progress here using @creedon's code from this post. Will be seeing if I can move it to the side rather than below, so my Status tags (Open Spots!) still show. creedon 1
Solution anniegerway Posted December 4 Author Solution Posted December 4 (edited) I was able to modify the code to get things to look how I wanted! Javascript and CSS below. Event Date must be added as the Secondary Meta Tag in Summary Block Settings. <script> $( () => { // Iterate over each summary item $( '.summary-item' ).each( function () { let $this = $( this ); // Get the metadata date text let metaDataDateText = $( '.summary-metadata-item--date:first', $this ).text(); if ( !metaDataDateText || !metaDataDateText.includes('–') ) return; // Extract start date and end date from the text let [startDateText, endDateText] = metaDataDateText.split(' – '); let startDate = new Date(startDateText); let endDate = new Date(endDateText); // Format the dates let startMonth = startDate.toLocaleString('default', { month: 'short' }); let startDay = startDate.getDate(); let endMonth = endDate.toLocaleString('default', { month: 'short' }); let endDay = endDate.getDate(); // Construct the new stacked date range element let $dateRange = $( `<div class="summary-thumbnail-event-date-range"> <div class="summary-thumbnail-event-date-start"> <span class="summary-thumbnail-event-date-month">${startMonth}</span> <span class="summary-thumbnail-event-date-day">${startDay}</span> </div> <span class="thumbnail-date-range-text">thru</span> <div class="summary-thumbnail-event-date-end"> <span class="summary-thumbnail-event-date-month">${endMonth}</span> <span class="summary-thumbnail-event-date-day">${endDay}</span> </div> </div>` ); // Replace the content of .summary-thumbnail-event-date-inner with the new range let $thumbnailEventDate = $( '.summary-thumbnail-event-date-inner', $this ); $thumbnailEventDate.empty().append($dateRange); }); }); </script> //summary block event range css// .sqs-block-summary-v2 .summary-block-setting-secondary-metadata-date .summary-metadata--secondary .summary-metadata-item--date { font-size: 0px;} .sqs-block-summary-v2 .summary-block-setting-secondary-metadata-date .summary-metadata--primary .summary-metadata-item:after {content: '' !important;} .thumbnail-date-range-text { font-size: 0.75em; color: @citron; font-family: proxima-nova, sans serif; } .summary-thumbnail-event-date-range { display: flex; /* Arrange start date, "thru", and end date horizontally */ align-items: center; /* Align all items vertically */ gap: 10px; /* Add space between each element */ padding-left: 10px; padding-right: 10px; } .summary-thumbnail-event-date-start, .summary-thumbnail-event-date-end { display: flex; /* Stack month and day vertically */ flex-direction: column; align-items: center; /* Center the text */ text-align: center; /* Ensure month and day are centered */ } .thumbnail-date-range-text { font-weight: bold; /* Make "thru" stand out */ font-size: 14px; /* Adjust font size as needed */ } Edited December 4 by anniegerway tuanphan 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment