Display Tagged CMS Items based on day of the week?

Hi there,

I’ve got an upcoming project where we’ll have a hero section on a recipe site that’ll need to display some recipes on Weekdays and others on Weekends. Does anyone know know how I’d be able to display recipes tagged as Weeknights only during the work week and recipes tagged as weekends only on Weekends?

Create two collection lists, one for weekend items the other filtered for weekday items. Give each collection list a class name, “weekend” for the first and the latter “weekday”.

Add custom code to the page that gets the day value of the current day and then sets the display accordingly.

var today = new Date();
var day = today.getDay();
if (day == 0 || day == 6) {
  weekday.style.display = 'none';
} else {
  weekend.style.display = 'none';
}
1 Like

@webdev Amazing!!! :raised_hands:

Thanks a bunch!

So I guess one could even expand on this, if there’s a burger Wednesday you could just add another line of code specific to day 3 with it’s own collection, or every day of the week?

Sky is the limit with code. Learn how to create conditionals … if...else - JavaScript | MDN

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.