修改wordpress官方twentyeleven主题评论模版为自己主题的模版

comments.php修改后的代码如下:

1
<;?php
1
/**
1
* The template for displaying Comments.
1
*
1
*/
1
?>;
1
<div id="comments">
1
<;?php if ( post_password_required() ) : ?>
1
<;p class="nopassword"><?php _e( 'This post is password protected. Enter the password to view any comments.' ); ?></p>
1
<;/div><!-- #comments -->
1
<;?php
1
/* Stop the rest of comments.php from being processed,
1
* but don't kill the script entirely -- we still have
1
* to fully load the template.
1
*/
1
return;
1
endif;
1
?>;
1
<?php // You can start editing here -- including this comment! ?>
1
<;?php if ( have_comments() ) : ?>
1
<;h2 id="comments-title">
1
<;?php
1
printf( _n( 'One thought on &;ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', get_comments_number() ),
1
number_format_i18n( get_comments_number() ), '<;span>' . get_the_title() . '</span>' );
1
?>;
1
</h2>
1
<;?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?>
1
<;nav id="comment-nav-above">
1
<;h1 class="assistive-text"><?php _e( 'Comment navigation'); ?></h1>
1
<;div class="nav-previous"><?php previous_comments_link( __( '&larr; Older Comments' ) ); ?></div>
1
<;div class="nav-next"><?php next_comments_link( __( 'Newer Comments &rarr;' ) ); ?></div>
1
<;/nav>
1
<;?php endif; // check for comment navigation ?>
1
<;ol class="commentlist">
1
<;?php
1
/* Loop through and list the comments. Tell wp_list_comments()
1
* to use twentyeleven_comment() to format the comments.
1
* If you want to overload this in a child theme then you can
1
* define twentyeleven_comment() and that will be used instead.
1
* See s_comment() in functions.php for more.
1
*/
1
wp_list_comments( array( 'callback' =>; 's_comment' ) );
1
?>;
1
</ol>
1
<;?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?>
1
<;nav id="comment-nav-below">
1
<;h1 class="assistive-text"><?php _e( 'Comment navigation' ); ?></h1>
1
<;div class="nav-previous"><?php previous_comments_link( __( '&larr; Older Comments' ) ); ?></div>
1
<;div class="nav-next"><?php next_comments_link( __( 'Newer Comments &rarr;' ) ); ?></div>
1
<;/nav>
1
<;?php endif; // check for comment navigation ?>
1
<;?php
1
/* If there are no comments and comments are closed, let's leave a little note, shall we?
1
* But we don't want the note on pages or post types that do not support comments.
1
*/
1
elseif ( ! comments_open() &;& ! is_page() && post_type_supports( get_post_type(), 'comments' ) ) :
1
?>;
1
<p class="nocomments"><?php _e( 'Comments are closed.' ); ?></p>
1
<;?php endif; ?>
1
<;div id="respond">
1
<;h3 id="reply-title">
1
<;?php comment_form_title(); ?>
1
<;small>
1
<;?php cancel_comment_reply_link(); ?>
1
<;/small></h3>
1
<;?php if ( get_option('comment_registration') && !$user_ID ) : ?>
1
<;p><?php printf(__('You must be <a href="%s">logged in</a> to post a comment.'), get_option('siteurl')."/wp-login.php?redirect_to=".urlencode(get_permalink()));?></p>
1
<;?php else : ?>
1
<;form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform" name="commentform">
1
<;p class="comment-notes">电子邮件地址不会被公开。 必填项已用<span class="required">*</span>标注</p>
1
<;?php if ( $user_ID ) : ?>
1
<;p><?php printf(__('Logged in as %s.'), '<a href="'.get_option('siteurl').'/wp-admin/profile.php">'.$user_identity.'</a>'); ?> <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="<?php _e('Log out of this account') ?>"><?php _e('Log out &raquo;'); ?></a></p>
1
<;?php else : ?>
1
<;p class="comment-form-author">
1
<;label for="author"><?php _e('Name'); ?><?php if ($req) _e('(required)'); ?></label>
1
<;span class="required">*</span>
1
<;input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" />
1
<;/p>
1
<;p class="comment-form-email">
1
<;label for="email"><?php _e('Mail');?> <?php if ($req) _e('(required)'); ?></label>
1
<;span class="required">*</span>
1
<;input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" />
1
<;/p>
1
<;p class="comment-form-url">
1
<;label for="url"><?php _e('Website'); ?></label>
1
<;input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" />
1
<;/p>
1
<;?php wp_smilies(); ?>
1
<;p class="comment-form-comment">
1
<;label for="comment">评论</label>
1
<;textarea name="comment" id="comment" rows="5" tabindex="4"></textarea></p>
1
<;?php endif; ?>
1
<;p class="form-submit"><input type="submit" id="submit" tabindex="5" value="<?php echo attribute_escape(__('发表评论')); ?>" /></p>
1
<;?php comment_id_fields(); ?>
1
<;?php do_action('comment_form', $post->ID); ?>
1
<;/form>
1
<;?php endif; // If registration required and not logged in ?>
1
<;/div>
1
<;/div><!-- #comments -->

在functions.php中加入如下函数:

1
/*评论模版*/
1
if ( ! function_exists( 's_comment' ) ) :
1
/**
1
* Template for comments and pingbacks.
1
*
1
* To override this walker in a child theme without modifying the comments template
1
* simply create your s_comment(), and that function will be used instead.
1
*
1
* Used as a callback by wp_list_comments() for displaying the comments.
1
*
1
*/
1
function s_comment( $comment, $args, $depth ) {
1
$GLOBALS['comment'] = $comment;
1
switch ( $comment->comment_type ) :
1
case 'pingback' :
1
case 'trackback' :
1
?>;
1
<li class="post pingback">
1
<;p><?php _e( 'Pingback:' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?></p>
1
<;?php
1
break;
1
default :
1
?>;
1
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
1
<;article id="comment-<?php comment_ID(); ?>" class="comment">
1
<;footer class="comment-meta">
1
<;div class="comment-author vcard">
1
<;?php
1
$avatar_size = 68;
1
if ( '0' != $comment->comment_parent )
1
$avatar_size = 39;
1
echo get_avatar( $comment, $avatar_size );
1
/* translators: 1: comment author, 2: date and time */
1
printf( __( '%1$s on %2$s <;span class="says">said:</span>' ),
1
sprintf( '<;span class="fn">%s</span>', get_comment_author_link() ),
1
sprintf( '<;a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
1
esc_url( get_comment_link( $comment->;comment_ID ) ),
1
get_comment_time( 'c' ),
1
/* translators: 1: date, 2: time */
1
sprintf( __( '%1$s at %2$s'), get_comment_date(), get_comment_time() )
1
)
1
);
1
?>
1
<;?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
1
<;/div><!-- .comment-author .vcard -->
1
<;?php if ( $comment->comment_approved == '0' ) : ?>
1
<;em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.'); ?></em>
1
<;br />
1
<;?php endif; ?>
1
<;/footer>
1
<;div class="comment-content"><?php comment_text(); ?></div>
1
<;div class="reply">
1
<;?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span>&darr;</span>'), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
1
<;/div><!-- .reply -->
1
<;/article><!-- #comment-## -->
1
<;?php
1
break;
1
endswitch;
1
}
1
endif; // ends check for s_comment()

css代码如下:

1
/*Comments */
1
#comments{
1
margin-top:10px;
1
}
1
#comments-title { color: #666; font-size: 10px; font-weight: 500; line-height: 2.6em; padding: 0 0 2.6em; text-transform: uppercase; }
1
.nopassword, .nocomments { color: #aaa; font-size: 24px; font-weight: 100; margin: 26px 0; text-align: center; }
1
.commentlist { list-style: none; margin: 0 auto; width: 68.9%; }
1
.content .commentlist { width: 100%; /* reset the width for the one-column and sidebar page layout */ }
1
.commentlist >; li.comment { background: #f6f6f6; border: 1px solid #ddd; -moz-border-radius: 3px; border-radius: 3px; margin: 0 0 1.625em; padding: 1.625em; position: relative; }
1
.commentlist .pingback { margin: 0 0 1.625em; padding: 0 1.625em; }
1
.commentlist .children { list-style: none; margin: 0; }
1
.commentlist .children li.comment { background: #fff; border-left: 1px solid #ddd; -moz-border-radius: 0 3px 3px 0; border-radius: 0 3px 3px 0; margin: 1.625em 0 0; padding: 1.625em; position: relative; }
1
.commentlist .children li.comment .fn { display: block; }
1
.comment-meta .fn { font-style: normal; }
1
.comment-meta { color: #666; font-size: 12px; line-height: 2.2em; }
1
.commentlist .children li.comment .comment-meta { line-height: 1.625em; margin-left: 50px; }
1
.commentlist .children li.comment .comment-content { margin: 1.625em 0 0; }
1
.comment-meta a { font-weight: bold; }
1
.comment-meta a:focus, .comment-meta a:active, .comment-meta a:hover { }
1
.commentlist .avatar { -moz-border-radius: 3px; border-radius: 3px; -webkit-box-shadow: 0 1px 2px #ccc; -moz-box-shadow: 0 1px 2px #ccc; box-shadow: 0 1px 2px #ccc; left: -102px; padding: 0; position: absolute; top: 0; }
1
.commentlist >; li:before { content: url(img/comment-arrow.png); left: -21px; position: absolute; }
1
.commentlist >; li.pingback:before { content: ''; }
1
.commentlist .children .avatar { background: none; -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; left: 2.2em; padding: 0; top: 2.2em; }
1
a.comment-reply-link { background: #eee; -moz-border-radius: 3px; border-radius: 3px; color: #666; display: inline-block; font-size: 12px; padding: 0 8px; text-decoration: none; }
1
a.comment-reply-link:hover, a.comment-reply-link:focus, a.comment-reply-link:active { background: #888; color: #fff; }
1
a.comment-reply-link >; span { display: inline-block; position: relative; top: -1px; }
1
/* Post author highlighting */
1
.commentlist >; li.bypostauthor { background: #ddd; border-color: #d3d3d3; }
1
.commentlist >; li.bypostauthor .comment-meta { color: #575757; }
1
.commentlist >; li.bypostauthor .comment-meta a:focus, .commentlist > li.bypostauthor .comment-meta a:active, .commentlist > li.bypostauthor .comment-meta a:hover { }
1
.commentlist >; li.bypostauthor:before { content: url(images/comment-arrow-bypostauthor.png); }
1
/* Post Author threaded comments */
1
.commentlist .children >; li.bypostauthor { background: #ddd; border-color: #d3d3d3; }
1
/* Comment Form */
1
#respond { background: #ddd; border: 1px solid #d3d3d3; -moz-border-radius: 3px; border-radius: 3px; margin: 0 auto 1.625em; padding: 1.625em; position: relative; width: 68.9%; }
1
#respond input[type="text"], #respond textarea { background: #fff; border: 4px solid #eee; -moz-border-radius: 5px; border-radius: 5px; -webkit-box-shadow: inset 0 1px 3px rgba(204, 204, 204, 0.95); -moz-box-shadow: inset 0 1px 3px rgba(204, 204, 204, 0.95); box-shadow: inset 0 1px 3px rgba(204, 204, 204, 0.95); position: relative; padding: 10px; text-indent: 80px; }
1
#respond .comment-form-author, #respond .comment-form-email, #respond .comment-form-url, #respond .comment-form-comment { position: relative; }
1
#respond .comment-form-author label, #respond .comment-form-email label, #respond .comment-form-url label, #respond .comment-form-comment label { background: #eee; -webkit-box-shadow: 1px 2px 2px rgba(204, 204, 204, 0.8); -moz-box-shadow: 1px 2px 2px rgba(204, 204, 204, 0.8); box-shadow: 1px 2px 2px rgba(204, 204, 204, 0.8); color: #555; display: inline-block; font-size: 13px; left: 4px; min-width: 60px; padding: 4px 10px; position: relative; top: 40px; z-index: 1; }
1
#respond input[type="text"]:focus, #respond textarea:focus { text-indent: 0; z-index: 1; }
1
#respond textarea { resize: vertical; width: 95%; }
1
#respond .comment-form-author .required, #respond .comment-form-email .required { color: #bd3500; font-size: 22px; font-weight: bold; left: 75%; position: absolute; top: 45px; z-index: 1; }
1
#respond .comment-notes, #respond .logged-in-as { font-size: 13px; }
1
#respond p { margin: 10px 0; }
1
#respond .form-submit { float: right; margin: -20px 0 10px; }
1
#respond input#submit { background: #222; border: none; -moz-border-radius: 3px; border-radius: 3px; -webkit-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3); -moz-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3); box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3); color: #eee; cursor: pointer; font-size: 15px; margin: 20px 0; padding: 5px 42px 5px 22px; position: relative; left: 30px; text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.3); }
1
#respond input#submit:active { background: #1982d1; color: #bfddf3; }
1
#respond #cancel-comment-reply-link { color: #666; margin-left: 10px; text-decoration: none; }
1
#respond .logged-in-as a:hover, #respond #cancel-comment-reply-link:hover { text-decoration: underline; }
1
.commentlist #respond { margin: 1.625em 0 0; width: auto; }
1
#reply-title { color: #373737; font-size: 24px; font-weight: bold; line-height: 30px; }
1
#cancel-comment-reply-link { color: #888; display: block; font-size: 10px; font-weight: normal; line-height: 2.2em; letter-spacing: 0.05em; position: absolute; right: 1.625em; text-decoration: none; text-transform: uppercase; top: 1.1em; }
1
#cancel-comment-reply-link:focus, #cancel-comment-reply-link:active, #cancel-comment-reply-link:hover { color: #ff4b33; }
1
#respond label { line-height: 2.2em; }
1
#respond input[type=text] { display: block; height: 24px; width: 75%; }
1
#respond p { font-size: 12px; }
1
p.comment-form-comment { margin: 0; }
1
.form-allowed-tags { display: none; }
1
/*表情样式定义*/
1
.wp_smilies { height:2px; padding-top:5px; }

改得比较粗糙,将就用用,哈哈。