我使用默认的WordPress注释系统,在我的注释模板中,我使用
<?php wp_list_comments() ?> 为了生成评论,我想知道如何修改评论日期?目前,它将于2014年2月11日上午6时27分显示完整的日期。在查看了WordPress编解码器之后,我似乎无法通过wp_list_comments args修改日期格式。
如何修改日期格式输出?
发布于 2014-05-29 08:00:32
您有两个选项: 1.您可以尝试修改wordpress核心文件wp-include/注释-template.php。要修改您希望拥有的日期格式(这看起来可能更容易,但我不建议您修改核心文件)。2.您可以创建一个自定义回调函数来显示您的注释,如下所示:您将调用该函数
现在,您可以在您的my_custom_comment文件中创建您的自定义函数function.php,它将简单地将默认列表替换为您的自定义列表格式。
现在在您的my_custom_comment中创建一个名为function.php的函数并修改日期格式
有关wp_list_comment的更多细节,请看一看评论())
function my_custom_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'] ); ?>
<?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; ?>发布于 2014-05-29 02:24:12
在注释项下的功能中,可以找到以下内容:
sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )或
printf( __('%1$s at %2$s'), get_comment_date(), get_comment_time())然后删除%2$s和,get_comment_time(),如下所示:
sprintf( __( '%1$s', 'twentytwelve' ), get_comment_date() )或
printf( __('%1$s'), get_comment_date())同样,如果您想修改日期,请使用下面的引用:时间
用途: get_comment_date('D,F‘)
希望这是你喜欢的东西。
发布于 2020-08-05 10:01:38
使用WordPress Codec文档,可以向wp_list_comments添加一个回调函数作为参数。
<?php
wp_list_comments( array(
'style' => 'ul',
'callback' => 'custom_comment_template'
));
?>从wp-include/class-walker-注释. Copy复制注释模板。并修改本节以满足您的需要。您可以在这里使用日期和时间格式用于WordPress。
function custom_comment_template(){
// Codes you have copies from wp-includes/class-walker-comment.php
// Or any design you want to use. You can use the hooks and filters
// from wp-includes/comment-template.php like
get_comment_author_link, get_comment_author
<div class="comment-meta commentmetadata">
<a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
<?php
/* translators: 1: Comment date, 2: Comment time. */
printf( __( '%1$s at %2$s' ), get_comment_date( '', $comment ), get_comment_time() );
?>
</a>
<?php edit_comment_link( __( '(Edit)' ), ' ', '' ); ?>
</div>
}https://stackoverflow.com/questions/23924170
复制相似问题