comments_open

函式
comments_open ( $post = null )
引數
  • (int|WP_Post) $post Post ID or WP_Post object. Default current post.
    Required:
    Default: null
返回值
  • (bool) True if the comments are open.
定義位置
相關方法
comment_typecomments_linkcomments_popup_linkis_comments_popupadd_comments_page
引入
1.5.0
棄用
-

comments_open: 這是一個WordPress的函式,用來確定一個特定的文章或頁面的評論是否開放。它接受一個文章的ID作為引數,如果評論是開放的,則返回真,否則返回假。

確定當前文章是否開放評論。

關於這個和類似的主題函式的更多資訊,請檢視《主題開發者手冊》中的{@link Conditional Tags}文章。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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 );
}

常見問題

FAQs
檢視更多 >