WordPress函数:is_preview 确定查询是用于文章预览还是用于页面预览

江河/ 2023年09月12日/ WordPress/ 浏览 485

函数原型:


is_preview(): bool


确定查询是用于文章预览还是用于页面预览


有关此主题函数和类似主题函数的更多信息,请参阅主题开发人员手册中的条件标记文章。


函数源码:


function is_preview() {
	global $wp_query;

	if ( ! isset( $wp_query ) ) {
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
		return false;
	}

	return $wp_query->is_preview();
}


使用举例:


function comments_template($file = '/comments.php', $separate_comments = false)
{
    global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;

    if (!(is_single() || is_page() || $withcomments) || empty($post)) {
        return;
    }

    if (is_preview()) {
        return;
    }
}


发表评论

暂无评论,抢个沙发...

客服 工单