
WordPress主题开发入门基础教程
comments_open ( $post = null )
comments_open: 这是一个WordPress的函数,用来确定一个特定的文章或页面的评论是否开放。它接受一个文章的ID作为参数,如果评论是开放的,则返回真,否则返回假。
确定当前文章是否开放评论。
关于这个和类似的主题函数的更多信息,请查看《主题开发者手册》中的{@link Conditional Tags}文章。
function comments_open( $post = null ) { $_post = get_post( $post ); $post_id = $_post ? $_post->ID : 0; $open = ( $_post && ( 'open' === $_post->comment_status ) ); /** * Filters whether the current post is open for comments. * * @since 2.5.0 * * @param bool $open Whether the current post is open for comments. * @param int $post_id The post ID. */ return apply_filters( 'comments_open', $open, $post_id ); }