在你的主题中需要找到wp_list_comments
它接受一些论点。其中一个论点是format
. 默认格式为html5
, 但还有一个/wp-includes/class-walker-comment.php
调用xhtml
.
以下是wp_list_comments
:
* @param string|array $args {
* Optional. Formatting options.
*
* @type object $walker Instance of a Walker class to list comments. Default null.
* @type int $max_depth The maximum comments depth. Default empty.
* @type string $style The style of list ordering. Default \'ul\'. Accepts \'ul\', \'ol\'.
* @type string $callback Callback function to use. Default null.
* @type string $end-callback Callback function to use at the end. Default null.
* @type string $type Type of comments to list.
* Default \'all\'. Accepts \'all\', \'comment\', \'pingback\', \'trackback\', \'pings\'.
* @type int $page Page ID to list comments for. Default empty.
* @type int $per_page Number of comments to list per page. Default empty.
* @type int $avatar_size Height and width dimensions of the avatar size. Default 32.
* @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts \'desc\', \'asc\'.
* @type bool $reverse_children Whether to reverse child comments in the list. Default null.
* @type string $format How to format the comments list.
* Default \'html5\' if the theme supports it. Accepts \'html5\', \'xhtml\'.
* @type bool $short_ping Whether to output short pings. Default false.
* @type bool $echo Whether to echo the output or return it. Default true.
* }
* @param array $comments Optional. Array of WP_Comment objects.
*/
function wp_list_comments( $args = array(), $comments = null ) {
您可以定义格式。
wp_list_comments( ... , \'myformat\', ...);
// create a callback
if( function_exists( \'myformat_comment\' ) )
{
$args[\'format\'] = \'myformat\';
$args[\'callback\'] = \'myformat_comment\';
}
在新功能中。
function myformat_comment( $comment, $depth, $args ){}
依据:
protected function html5_comment( $comment, $depth, $args ) {
$tag = ( \'div\' === $args[\'style\'] ) ? \'div\' : \'li\';
?>
<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? \'parent\' : \'\', $comment ); ?>>
<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
<footer class="comment-meta">
<div class="comment-author vcard">
<?php if ( 0 != $args[\'avatar_size\'] ) echo get_avatar( $comment, $args[\'avatar_size\'] ); ?>
<?php printf( __( \'%s <span class="says">says:</span>\' ), sprintf( \'<b class="fn">%s</b>\', get_comment_author_link( $comment ) ) ); ?>
</div><!-- .comment-author -->
<div class="comment-metadata">
<a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
<time datetime="<?php comment_time( \'c\' ); ?>">
<?php
/* translators: 1: comment date, 2: comment time */
printf( __( \'%1$s at %2$s\' ), get_comment_date( \'\', $comment ), get_comment_time() );
?>
</time>
</a>
<?php edit_comment_link( __( \'Edit\' ), \'<span class="edit-link">\', \'</span>\' ); ?>
</div><!-- .comment-metadata -->
<?php if ( \'0\' == $comment->comment_approved ) : ?>
<p class="comment-awaiting-moderation"><?php _e( \'Your comment is awaiting moderation.\' ); ?></p>
<?php endif; ?>
</footer><!-- .comment-meta -->
<div class="comment-content">
<?php comment_text(); ?>
</div><!-- .comment-content -->
<?php
comment_reply_link( array_merge( $args, array(
\'add_below\' => \'div-comment\',
\'depth\' => $depth,
\'max_depth\' => $args[\'max_depth\'],
\'before\' => \'<div class="reply">\',
\'after\' => \'</div>\'
) ) );
?>
</article><!-- .comment-body -->
<?php
}