gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 02:48:13 25 4
gpt4 key购买 nike

我想在我的 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 } ?>

现在我需要修改日期格式和评论标签我该怎么做

最佳答案

使用这个过滤器。

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

关于wordpress - 如何修改wordpress列表评论中的日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18350375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com