Wordpress 主题制作-添加评论页 comments.php

在主题文件夹下创建 comments.php
内容如下

<?php
    if (isset($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
        die ('Please do not load this page directly. Thanks!');
?>

<!– Comment’s List –>
   <h3>Comments</h3>
   <div class="hr dotted clearfix"> </div>
   <ol class="commentlist">
         <?php
            if (!empty($post->post_password) && $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) {
            // if there's a password
            // and it doesn't match the cookie
         ?>
            <li>
                <p><a href="#addcomment">请输入密码再查看评论内容.</a></p>
            </li>
         <?php
             } else if ( !comments_open() ) {
         ?>
         <li>
             <p><a href="#addcomment">评论功能已经关闭!</a></p>
         </li>
         <?php
             } else if ( !have_comments() ) {
         ?>
         <li >
             <p><a href="#addcomment">还没有任何评论,你来说两句吧</a></p>
         </li>
         <?php
             } else {
                 wp_list_comments('type=comment&callback=aurelius_comment');
             }
         ?>
   </ol>
   <div class="hr clearfix"> </div>
   <!– Comment Form –>
   <?php if ( comments_open() ) : ?>
    <?php if ( get_option('comment_registration') && !$user_ID ) : ?>
    <p><?php printf(__('你需要先 <a href="%s">登录</a> 才能发表评论.'), get_option('siteurl')."/wp-login.php?redirect_to=".urlencode(get_permalink()));?></p>
    <?php else : ?>
    <?php $defaults = array(
        'comment_notes_before' => '',
        'label_submit'         => __( '提交评论' ),
        'comment_notes_after' =>''
    );
    comment_form($defaults);
     endif;
    else :  ?>
    <p><?php _e('对不起评论已经关闭.'); ?></p>
    <?php endif; ?>

在需要显示评论框的地方,加入 <?php comments_template(); ?>

此教程目前不含样式,各位可以自行美化。
评论页分为两部分,一部分是显示已有的评论,第二部分是显示评论框,供用户添加新的评论


评论

《“Wordpress 主题制作-添加评论页 comments.php”》 有 2 条评论

  1. 样式还差好多,慢慢美化

发表回复