I own a small restaurant and am trying to display the weekly lunch menu on my website.
Right now there is only one permanent menu showing on the website but i would like to create a rotation of 4 menus for each week of the month. The menus are images and i want to only display one of them each week starting monday.
Basically i have 4 images and i want to display 1 one of them (through a loop maybe?) every week starting monday.
I have a basic understanding in javascript and my website is made with wordpress.
all and any suggestions are appreciated 🙂
I tried googling a way to display content based on date but couldnt understand how the date() method works. another issue was figuring out how to pinpoint monday out of the weekdays.
2
Answers
I don’t suggest using only the client to handle this but if it’s simply changing images, we can set an origin Monday and then calculate the weeks after that.
Every time the page loads we will get number of the weeks from the origin time up to now, we then can use that number to choose an index of our image sources.
This is my solution:
HTML:
Javascript:
Handling dates in JS difficult due timezone offsets and daylight time savings which are dynamic and change by governments, but for non-critical cases (not medical or financial) you could get your week index using the reminder operator from day count from the Unix epoch start. Then you can adjust the index to any offset you like and get an image from an image array of length 4.