添加评论日期给评论作者div wordpress

时间:2016-06-05 12:37:52

标签: wordpress

我正在努力学习使用wordpress。 我正在尝试更改评论布局,我想加入评论日期来评论作者数据。但我没有得到它。例如,我有第一张图片中的内容,但我想要的是第二张图片。你能帮帮忙吗?非常感谢!

enter image description here enter image description here

1 个答案:

答案 0 :(得分:1)

我认为您的主要问题是您想要仅使用css自定义日期的方式,但这非常困难。 您最好的办法是拥有自己的自定义注释码。

Wordpress让你有自己的评论代码。

例如,当您调用注释模板代码而不是执行此操作时:

wp_list_comments( array(
  'style'       => 'ol',
  'short_ping'  => true,
  'avatar_size' => 42,
) );

您可以这样做:

<ol class="commentlist">
<?php wp_list_comments( 'type=comment&callback=mytheme_comment' ); ?>
</ol>

在function.php文件中,你可以添加mytheme_comment函数和wp的原始注释代码,并重新排列类和html代码的位置,这样你就可以得到你想要的日期。

function mytheme_comment($comment, $args, $depth) {
    if ( 'div' === $args['style'] ) {
        $tag       = 'div';
        $add_below = 'comment';
    } else {
        $tag       = 'li';
        $add_below = 'div-comment';
    }
    ?>
    <<?php echo $tag ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
    <?php if ( 'div' != $args['style'] ) : ?>
        <div id="div-comment-<?php comment_ID() ?>" class="comment-body">
    <?php endif; ?>
    <div class="comment-author vcard">
        <?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
        <?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
    </div>
    <?php if ( $comment->comment_approved == '0' ) : ?>
         <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em>
          <br />
    <?php endif; ?>

    <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
        <?php
        /* translators: 1: date, 2: time */
        printf( __('%1$s at %2$s'), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), '  ', '' );
        ?>
    </div>

    <?php comment_text(); ?>

    <div class="reply">
        <?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
    </div>
    <?php if ( 'div' != $args['style'] ) : ?>
    </div>
    <?php endif; ?>
    <?php
    }

在默认代码中,您可以看到代码:

   <?php
      /* translators: 1: date, 2: time */
      printf( __('%1$s at %2$s'), get_comment_date(),  get_comment_time() ); 
   ?>

是为您提供日期信息的。

希望你明白这一点。

这是关于此的原始WP文档: wp list comments

相关问题