假设您希望有条件地输出内容,这取决于您是否在给定的静态页面集上,根据页面ID,您可以简单地将代码包装在is_page()
有条件的
要确定当前用户是否已登录,可以使用is_user_logged_in()
有条件的
例如
// Array of Page IDs
$page_ids = array( 2506,2516,2512,2513,2509,2515,2510,2508,2514,2511,2507 );
// If the current context is a static page with one of the above IDs
// and the current user is logged in
if ( is_page( $page_ids ) && is_user_logged_in() ) {
// This is one of our pages
// Do something
}
或者对于当前用户未登录的情况:
// Array of Page IDs
$page_ids = array( 2506,2516,2512,2513,2509,2515,2510,2508,2514,2511,2507 );
// If the current context is a static page with one of the above IDs
// and the current user is NOT logged in
if ( is_page( $page_ids ) && ! is_user_logged_in() ) {
// This is one of our pages
// Do something
}