自定义TwentyEleven评论模板

时间:2012-10-16 作者:user1255049

通常我不会在我的网站上使用评论,但是我使用评论功能作为一种实时提要推荐页面。为了做到这一点,我借用了comments.php 以及functions.php 来自TwentyEleven主题。我目前正在努力解决的是评论/表单在上的显示方式the site理想情况下,我希望表格在左边(内侧.content-left) 注释列表位于右侧(内部.content-right). 目前,评论列表位于.content-left 我希望它在哪里.content-right. 如何将其从左侧移除?

共有php

<?php
/*
Template Name: Share
*/
?>

<?php get_header(); ?>

<h1>We\'re All Ears.</h1>
<div class="content-left">

    <?php comments_template(); ?> 

</div><!-- end content-left -->
<div class="content-right">

    <?php wp_list_comments( array( \'callback\' => \'twentyeleven_comment\' )); ?></ul>

</div><!-- end content-right -->

<?php get_footer(); ?>
评论。php

<?php
/**
 * The template for displaying Comments.
 *
 * The area of the page that contains both current comments
 * and the comment form. The actual display of comments is
 * handled by a callback to twentyeleven_comment() which is
 * located in the functions.php file.
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */
?>
    <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.\', \'twentyeleven\' ); ?></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() ) : ?>

        <?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\', \'twentyeleven\' ); ?></h1>
            <div class="nav-previous"><?php previous_comments_link( __( \'&larr; Older Comments\', \'twentyeleven\' ) ); ?></div>
            <div class="nav-next"><?php next_comments_link( __( \'Newer Comments &rarr;\', \'twentyeleven\' ) ); ?></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 twentyeleven_comment() in twentyeleven/functions.php for more.
                 */
                wp_list_comments( array( \'callback\' => \'twentyeleven_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\', \'twentyeleven\' ); ?></h1>
            <div class="nav-previous"><?php previous_comments_link( __( \'&larr; Older Comments\', \'twentyeleven\' ) ); ?></div>
            <div class="nav-next"><?php next_comments_link( __( \'Newer Comments &rarr;\', \'twentyeleven\' ) ); ?></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.\', \'twentyeleven\' ); ?></p>
    <?php endif; ?>

    <?php comment_form(); ?>

</div><!-- #comments -->
功能。php

<?php 

if ( ! function_exists( \'twentyeleven_comment\' ) ) :
/**
 * Template for comments and pingbacks.
 *
 * To override this walker in a child theme without modifying the comments template
 * simply create your own twentyeleven_comment(), and that function will be used instead.
 *
 * Used as a callback by wp_list_comments() for displaying the comments.
 *
 * @since Twenty Eleven 1.0
 */
function twentyeleven_comment( $comment, $args, $depth ) {
    $GLOBALS[\'comment\'] = $comment;
    switch ( $comment->comment_type ) :
        case \'pingback\' :
        case \'trackback\' :
    ?>
    <li class="post pingback">
        <p><?php _e( \'Pingback:\', \'twentyeleven\' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( \'Edit\', \'twentyeleven\' ), \'<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>\', \'twentyeleven\' ),
                            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\', \'twentyeleven\' ), get_comment_date(), get_comment_time() )
                            )
                        );
                    ?>

                    <?php edit_comment_link( __( \'Edit\', \'twentyeleven\' ), \'<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.\', \'twentyeleven\' ); ?></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>\', \'twentyeleven\' ), \'depth\' => $depth, \'max_depth\' => $args[\'max_depth\'] ) ) ); ?>
            </div><!-- .reply -->
        </article><!-- #comment-## -->

    <?php
            break;
    endswitch;
}
endif; // ends check for twentyeleven_comment()

?>
此外,如何让注释列表显示用户名以及其他字段的信息?

2 个回复
最合适的回答,由SO网友:Mridul Aggarwal 整理而成

将其从左侧移除。删除包含以下内容的行wp_list_comments 来自评论。php

显示用户名添加comment_author();, 用于电子邮件comment_author_email(); &;供url使用if(get_comment_author_url()) comment_author_url();. comment_text() 已经存在了。

这些都放在函数中函数内部的标记中。php

SO网友:pensebien

在您的示例中share.php,在这两种情况下,您都使用两次加载内容查询<?php comments_template(); ?>wp_list_comments() 功能。

wp_list_comments() 列出特定帖子上的评论,并在评论中使用。php。comments.php 主要是在你的theme folders 或者,如果WordPress没有找到它,则会使用默认主题文件夹中的文件。也就是说,如果您没有删除WordPress附带的默认主题。

comments_template() 调用注释模板。在您的情况下,它将以您的主题开始,然后是默认的主题文件夹。本质上,此函数将调用wp_list_comment 在上面

要在左侧显示评论表单并在右侧显示列表评论内容,您需要修改comment.php file 你有。您使用custom function through the callback 仅当您要修改structure of the comment template in terms of author name, how dates is showed, add more metadata to the comment, 大概voting on comment.

共有php

<?PHP
  /*
  Template Name: Share
  */
?>

 <?php get_header(); ?>

 <h1>We\'re All Ears.</h1>
 <div class="comment-content">
   <?php wp_list_comments( array( \'callback\' => \'twentyeleven_comment\' )); ?>
 </div>
评论。php将其他所有内容放入

 <div class="content-left">
  <?php comment_form(); ?>
 </div>
 <div class="content-right">
  //Everything gos here except `<?php comment_form(); ?>`
 </div>

结束

相关推荐

将do_action()替换为Comments.php中的普通提交表单

在我的评论中。php我有以下代码: <input name=\"submit\" type=\"submit\" id=\"submit\" tabindex=\"5\" value=\"Submit\" /> <?php comment_id_fields(); ?> <?php do_action(\'comment_form\', $post->ID); ?> 有没有办法用一个简单的提交表单来替换此代码?并且不使用:do\\u