函數(shù)官方參考:
https://codex.wordpress.org/Function_Reference/have_comments
開發(fā)評論模板時(shí)遇到一個(gè)問題,當(dāng)博文有評論時(shí),一切正常,

當(dāng)博文無評論時(shí),評論框不顯示。

原因:
是判斷函數(shù):have_comments()的問題
我在代碼中是這樣寫的:
if ( have_comments() ) : ?>
?
????
???? comment_form(array(
????
'comment_notes_after' => '
請?jiān)L問我們的 隱私政策 頁面。
',
????????'title_reply'=>'添加新評論',
????//評論輸入框上方文字
????????'comment_notes_before'=>'
' . __( '' ) . ( $req ? $required_text : '' ) . '
',
????//評論輸入框
???? ???'comment_field' => '
' . _x( '', 'noun' ) . '
',
????
????
????????'label_submit'=>__( '提交評論' ),
????//強(qiáng)制登陸留言
????????'must_log_in'=>'
' . sprintf( __( '您必須e登陸 才能留言.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '
',
????//登陸為
????????'logged_in_as'=>'
' . sprintf( __( '當(dāng)前身份為:%2$s,您需要退出嗎?' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '
',
));
????
?>
????
????<h2 class="comments-title">
printf( _nx( '一個(gè)想法 "%2$s"', '"%2$s"共有 %1$s 條評論 ', get_comments_number(), '注釋標(biāo)題', 'mirages' ),
number_format_i18n( get_comments_number() ), '' . get_the_title() . '' );
?>h2><ol class="comment-list">
wp_list_comments( array(
'style' => 'ol',
'short_ping' => true,
'avatar_size' => 120,//頭像大小
????????????????????'reply_text' =>'回復(fù)',/*回復(fù)文字*/
????????????????????'callback' => 'mirages_comment'/*使用自定義回調(diào)函數(shù)控制評論的外觀*/
) );
?>ol>
????
????<div class="pagination"> paginate_comments_links(); ?>
div>
????
????
// Are there comments to navigate through?
????????????//是否有可瀏覽的注釋?if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
?> endif; // Check for comment navigation(檢查注釋導(dǎo)航) ?>
????
if ( ! comments_open() && get_comments_number() ) : ?><p class="no-comments"> _e( '評論已關(guān)閉.' , 'mirages' ); ?>p> endif; ?>
endif; // have_comments() ?>
?
當(dāng)博文中無評論時(shí),函數(shù)判斷為假,函數(shù)判斷中的內(nèi)容不顯示。
當(dāng)博文中有評論時(shí),函數(shù)判斷為真,顯示判斷中的內(nèi)容。
在此處,這個(gè)函數(shù)是用來控制評論中的博文標(biāo)題是否顯示的,而我卻在其中把評論框也包進(jìn)去了。
應(yīng)該是這樣寫:
if ( have_comments() ) : ?>
<h2 class="comments-title">
printf( _nx( '一個(gè)想法 "%2$s"', '"%2$s"共有 %1$s 條評論 ', get_comments_number(), '注釋標(biāo)題', 'mirages' ),
number_format_i18n( get_comments_number() ), '' . get_the_title() . '' );
?>h2>
endif; // end have_comments() ?>