(Wordpress Multisite) Display page as homepage in chosen weekdays

给你一囗甜甜゛ 提交于 2019-12-24 08:47:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!