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

作者:admin发表时间:2012-3-29 评论:3 点击 31,677+

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

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

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

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

css代码如下:

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

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

顶一下 0 踩一下 0

你可能对以下内容感兴趣!

  1. 谷歌打不开,wordpress后台反应慢
  2. wordpress免费的备份插件BackUpWor...
  3. 谈一谈让wordpress更安全
  4. wordpress添加自定义默认头像
  5. wordpress本地测试站开启伪静态
  6. 给wordpress友情链接页面添加Favicon...
  7. JQuery和CSS 版wordpress 弹性伸...
  8. wordpress 自定义评论表情

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

发表回复

*

w_0002.gif w_0009.gif w_0007.gif w_0011.gif w_0005.gif w_0008.gif w_0010.gif w_0003.gif w_0012.gif w_0001.gif w_0006.gif