I have a project where I need to display an alternating food menu each week.
- i.e. menu1 on week1, menu2 on week2 then back to week1 etc.
- I’ve created custom post types for each menu (menu1 & menu2).
Ideally, if the user wanted to see what the food menu was going to be next week, they would click on a calendar day a week from today & the food menu would display week2’s food menu.
I could deal with changing the food menu per week by having different custom pages to pull the different custom post types, but this does not solve the above requirement of what was on next week.
You can use PHP’s
date
functionality:All you have to do then, is to map the numbers to the according menus (i.e., custom post types).
Firt of all I think you have to set a configuration for the start week: i.e. the first week you start with menu 1.
Probably is better also configure a day of start, in this way you can choose the day of week in which the menu change.
My proposal is to set 2 configuration:
$start_date
and$menu_duration
, in this way you your code is more flexible.After that you can use some logic to:
The code for that can be placed in a plugin and the configuration can be placed in a custom admin page, but for semplicity of answer I will put it in a page template file.
I assume here that your custom post type is named ‘menus’.
Of course, the display part is just an axample.
Note that code is all untested.