創(chuàng)建留言模板comments.php 在該模板中添加以下代碼 ,在需要使用留言的地方添加調(diào)用comments_template()標(biāo)簽即可

<div>
<h2>評論</h2>
<div>
    <ul>
      <? if(!comments_open() ){?>//判斷評論功能是否已關(guān)閉,如果關(guān)閉提示 評論功能已經(jīng)關(guān)閉
        <li>
          <a href="#respond">評論功能已經(jīng)關(guān)閉</a></li>
        <? }else if( post_password_required()){?>//post_password_required()設(shè)置輸入密碼才能查看文章 編輯文章右側(cè)設(shè)置密碼保護(hù)
          <li>
            <a href="#respond">請輸入密碼查看評論內(nèi)容</a></li>
          <? }else if(!have_comments()){?>// 判斷當(dāng)前文章是否有評論
            <li>
              <a href="#respond">還沒有評論說兩句吧</a></li>
            <? }else{wp_list_comments(); }?>//獲取所有評論</ul>
</div>
<div>
    <? if(get_option( 'comment_registration') && !is_user_logged_in() ){ ?>// 判斷用戶是否有登陸
      <p>你必須<a href="<? echo wp_login_url(get_permalink()); ?>">登陸</a>才可以發(fā)布評論</p>
      <? }else if(comments_open()){comment_form();} ?>//輸出評論窗口
</div>
</div>