如何修改wordpress列表评论中的日期格式

问题描述 投票:0回答:2

我想修改我的评论列表详细日期,在我的 WordPress 主题中显示重播按钮等,我看到了此代码并使用它,但我需要修改日期格式以及标签和标题等,我使用此代码

<?php /*----------------------------------- Template for Comments ---------------------------------------*/ ?>

<div id="comments">

    <?php if ( post_password_required() ) : ?>

    <p class="text-error"><?php _e( 'This post is password protected. Enter the password to view any comments.', 'cusmagazines' ); ?></p>

</div>

    <?php
        return;
        endif;
    ?>

<?php if ( have_comments() ) : ?>

    <h2 id="comments-title">
        <?php
            printf( _n( 'One Comment', '%1$s Comments', get_comments_number(), 'cusmagazines' ), number_format_i18n( get_comments_number() ) );
        ?>
        <a class="goto goto-respond" href="#respond" title="Add Your Comment">( Add Comment )</a>
    </h2>

    <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>

    <div id="comment-nav-above">

        <h1 class="assistive-text"><?php _e( 'Comment navigation', 'cusmagazines' ); ?></h1>
        <div class="nav-previous"><?php previous_comments_link( __( '&larr; Older Comments', 'cusmagazines' ) ); ?></div>
        <div class="nav-next"><?php next_comments_link( __( 'Newer Comments &rarr;', 'cusmagazines' ) ); ?></div>

    </div>

    <?php endif; ?>

    <div class="commentlist">

        <?php 

        $args = array(
        'walker'            => null,
        'max_depth'         => 3,
        'style'             => 'div',
        'callback'          => 'custhemes_comment',
        'end-callback'      => null,
        'type'              => 'all',
        'page'              => null,
        'per_page'          => null,
        'avatar_size'       => 45,
        'reverse_top_level' => null,
        'reverse_children'  => null ); 

        wp_list_comments($args); 

        ?>

    </div>

    <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>

    <div id="comment-nav-below">

        <h1 class="assistive-text"><?php _e( 'Comment navigation', 'cusmagazines' ); ?></h1>
        <div class="nav-previous"><?php previous_comments_link( __( '&larr; Older Comments', 'cusmagazines' ) ); ?></div>
        <div class="nav-next"><?php next_comments_link( __( 'Newer Comments &rarr;', 'cusmagazines' ) ); ?></div>

    </div>

    <?php endif; ?>

<?php

    elseif ( ! comments_open() && ! is_page() && post_type_supports( get_post_type(), 'comments' ) ) :
?>
    <p class="nocomments"><?php _e( 'Comments are closed.', 'cusmagazines' ); ?></p>

<?php endif; ?>

我将此代码添加到 function.php

<?php function custhemes_comment($comment, $args, $depth) {

        $GLOBALS['comment'] = $comment;

        extract($args, EXTR_SKIP);

        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'] ); ?>

    </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">

        <?php printf(__('<span class="author-name">%s</span>'), get_comment_author_link()); ?>

        <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">

            <?php printf( __('%1$s - %2$s'), get_comment_date('d.m.Y'),  get_comment_time()); ?>

        </a>

            <?php edit_comment_link(__('(Edit)'),'  ','' );

        ?>

    </div>

    <div class="comment-text"><?php comment_text(); ?></div>

    <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 wordpress date comments
2个回答
5
投票

使用这个过滤器。

 add_filter( 'get_comment_date', 'wpse_comment_date_18350375' );    
 function wpse_comment_date_18350375( $date ) {
   $date = date("m.d.y");   
   return $date;
 }

© www.soinside.com 2019 - 2024. All rights reserved.