问题
How can I make chosen page to display as homepage of my multisite site depending on a week day? I have this function to display my page depending if user is logged in or not, next I want it to work differently during tuesday (picking different pages as follows):
function switch_homepage() {
if ( is_main_site() ) {
// Do stuff only for the main site
if ( is_user_logged_in() ) {
$page = 4284; // for logged in users
update_option( 'page_on_front', $page );
update_option( 'show_on_front', 'page' );
} else {
$page = 4133; // for logged out users
update_option( 'page_on_front', $page );
update_option( 'show_on_front', 'page' );
}
}
}
回答1:
You can do something like this:
$today = date('l');
if ($today == 'Tuesday') {
// your update_option() goes here
}
回答2:
This function will consider the time zone from the general settings in the current WordPress site.
function get_wp_week_day() {
return get_date_from_gmt( date( 'Y-m-d H:i:s', time() ), 'l' );
}
if ( get_wp_week_day() == 'Tuesday' ) {
/* do stuff only on Tuesday */
}
来源:https://stackoverflow.com/questions/44217875/wordpress-multisite-display-page-as-homepage-in-chosen-weekdays