mirror of
https://github.com/WordPress/WordPress.git
synced 2024-06-26 06:45:07 +02:00
Improve wp_list_comments() markup.
* Whitespace cleanup * Accepts format=html5 which uses some of the HTML5 elements * Some helpful HTML comments to help untangle the HTML * Other misc code cleanup props lancewillett, obenland, georgestephanis. fixes #20088. git-svn-id: http://core.svn.wordpress.org/trunk@23694 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
a224d8aaf7
commit
b3f6427c6f
|
@ -1244,11 +1244,11 @@ class Walker_Comment extends Walker {
|
||||||
case 'div':
|
case 'div':
|
||||||
break;
|
break;
|
||||||
case 'ol':
|
case 'ol':
|
||||||
echo "<ol class='children'>\n";
|
echo '<ol class="children">' . "\n";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case 'ul':
|
case 'ul':
|
||||||
echo "<ul class='children'>\n";
|
echo '<ul class="children">' . "\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1268,11 +1268,11 @@ class Walker_Comment extends Walker {
|
||||||
case 'div':
|
case 'div':
|
||||||
break;
|
break;
|
||||||
case 'ol':
|
case 'ol':
|
||||||
echo "</ol>\n";
|
echo "</ol><!-- .children -->\n";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case 'ul':
|
case 'ul':
|
||||||
echo "</ul>\n";
|
echo "</ul><!-- .children -->\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1330,50 +1330,18 @@ class Walker_Comment extends Walker {
|
||||||
$GLOBALS['comment_depth'] = $depth;
|
$GLOBALS['comment_depth'] = $depth;
|
||||||
$GLOBALS['comment'] = $comment;
|
$GLOBALS['comment'] = $comment;
|
||||||
|
|
||||||
if ( !empty($args['callback']) ) {
|
if ( !empty( $args['callback'] ) ) {
|
||||||
call_user_func($args['callback'], $comment, $args, $depth);
|
call_user_func( $args['callback'], $comment, $args, $depth );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
extract($args, EXTR_SKIP);
|
if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) {
|
||||||
|
$this->ping( $comment, $depth, $args );
|
||||||
if ( 'div' == $args['style'] ) {
|
} elseif ( 'html5' === $args['format'] ) {
|
||||||
$tag = 'div';
|
$this->html5_comment( $comment, $depth, $args );
|
||||||
$add_below = 'comment';
|
|
||||||
} else {
|
} else {
|
||||||
$tag = 'li';
|
$this->comment( $comment, $depth, $args );
|
||||||
$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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1385,17 +1353,126 @@ class Walker_Comment extends Walker {
|
||||||
* @param int $depth Depth of comment.
|
* @param int $depth Depth of comment.
|
||||||
* @param array $args
|
* @param array $args
|
||||||
*/
|
*/
|
||||||
function end_el(&$output, $comment, $depth = 0, $args = array() ) {
|
function end_el( &$output, $comment, $depth = 0, $args = array() ) {
|
||||||
if ( !empty($args['end-callback']) ) {
|
if ( !empty( $args['end-callback'] ) ) {
|
||||||
call_user_func($args['end-callback'], $comment, $args, $depth);
|
call_user_func( $args['end-callback'], $comment, $args, $depth );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( 'div' == $args['style'] )
|
if ( 'div' == $args['style'] )
|
||||||
echo "</div>\n";
|
echo "</div><!-- #comment-## -->\n";
|
||||||
else
|
else
|
||||||
echo "</li>\n";
|
echo "</li><!-- #comment-## -->\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 3.6
|
||||||
|
* @access protected
|
||||||
|
*
|
||||||
|
* @param object $comment
|
||||||
|
* @param int $depth Depth of comment.
|
||||||
|
* @param array $args
|
||||||
|
*/
|
||||||
|
protected function ping( $comment, $depth, $args ) {
|
||||||
|
$tag = ( 'div' == $args['style'] ) ? 'div' : 'li';
|
||||||
|
?>
|
||||||
|
<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
|
||||||
|
<div class="comment-body">
|
||||||
|
<?php _e( 'Pingback:' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 3.6
|
||||||
|
* @access protected
|
||||||
|
*
|
||||||
|
* @param object $comment Comment to display.
|
||||||
|
* @param int $depth Depth of comment.
|
||||||
|
* @param array $args Optional args.
|
||||||
|
*/
|
||||||
|
protected function comment( $comment, $depth, $args ) {
|
||||||
|
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 ( 0 != $args['avatar_size'] ) 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 ( '0' == $comment->comment_approved ) : ?>
|
||||||
|
<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 esc_url( 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
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 3.6
|
||||||
|
* @access protected
|
||||||
|
*
|
||||||
|
* @param object $comment Comment to display.
|
||||||
|
* @param int $depth Depth of comment.
|
||||||
|
* @param array $args Optional 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( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
|
||||||
|
<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( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
|
||||||
|
</div><!-- .comment-author -->
|
||||||
|
|
||||||
|
<div class="comment-metadata">
|
||||||
|
<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
|
||||||
|
<time datetime="<?php comment_time( 'c' ); ?>">
|
||||||
|
<?php printf( _x( '%1$s at %2$s', '1: date, 2: time' ), get_comment_date(), 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 -->
|
||||||
|
|
||||||
|
<div class="reply">
|
||||||
|
<?php comment_reply_link( array_merge( $args, array( 'add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
|
||||||
|
</div><!-- .reply -->
|
||||||
|
</article><!-- .comment-body -->
|
||||||
|
<?php
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1417,8 +1494,21 @@ function wp_list_comments($args = array(), $comments = null ) {
|
||||||
$comment_alt = $comment_thread_alt = 0;
|
$comment_alt = $comment_thread_alt = 0;
|
||||||
$comment_depth = 1;
|
$comment_depth = 1;
|
||||||
|
|
||||||
$defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all',
|
$defaults = array(
|
||||||
'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '');
|
'walker' => null,
|
||||||
|
'max_depth' => '',
|
||||||
|
'style' => 'ul',
|
||||||
|
'callback' => null,
|
||||||
|
'end-callback' => null,
|
||||||
|
'type' => 'all',
|
||||||
|
'page' => '',
|
||||||
|
'per_page' => '',
|
||||||
|
'avatar_size' => 32,
|
||||||
|
'reverse_top_level' => null,
|
||||||
|
'reverse_children' => '',
|
||||||
|
'format' => 'xhtml', // or html5
|
||||||
|
'short_ping' => false,
|
||||||
|
);
|
||||||
|
|
||||||
$r = wp_parse_args( $args, $defaults );
|
$r = wp_parse_args( $args, $defaults );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user