I've seen various sites using the built in wordpress comment system with a custom callback (to generate their own html different than that if the built in comments in wordpress) adding numbers to comments on their site.
我已经看到各种网站使用内置的wordpress评论系统与自定义回调(生成自己的html不同,如果在wordpress中的内置评论)添加数字到他们的网站上的评论。
Ala - http://mobile.smashingmagazine.com/2013/08/12/creating-high-performance-mobile-websites/
Ala - http://mobile.smashingmagazine.com/2013/08/12/creating-high-performance-mobile-websites/
Each comment has a number beside it. After doing a whole lot of searching I can't find any built in function of wordpress that does this.
每条评论旁边都有一个数字。经过大量的搜索后,我找不到任何内置的wordpress功能。
I'm using a custom calllback for my comments.
我正在使用自定义的calllback进行评论。
function mytheme_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">
<div class="rounded">
<?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
</div> <!-- end div rounded -->
</div> <!-- end div vcard -->
<div class="comment-meta commentmetadata">
<?php printf(__('<cite class="fn">%s</cite> <span class="says"></span>'), get_comment_author_link()) ?>
<a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
<?php
printf( __('%1$s at %2$s'), comment_time('F j, Y g:i a')) ?></a><?php edit_comment_link(__('(Edit)'),' ','' );
?>
</a>
<?php if ($comment->comment_approved == '0') : ?>
<em class="comment-awaiting-moderation">
<?php _e('Your comment is awaiting moderation.') ?>
</em>
<br />
<?php endif; ?>
</div> <!-- end div commentmetadata -->
<div class="commentsholder">
<?php comment_text() ?>
</div> <!-- end div commentsholder -->
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div> <!-- end div reply -->
<?php echo '<div style="clear:both"></div>' ?>
<?php if ( 'div' != $args['style'] ) : ?>
</div> <!-- end div commentid -->
<?php endif; ?>
<?php
}
Can anyone give me any idea how to number each comment?
任何人都可以告诉我如何编号每个评论?
2 个解决方案
#1
0
Look at the twentytwelve theme. It uses an ordered list.
看看二十世纪的主题。它使用有序列表。
<ol class="commentlist">
<?php wp_list_comments( array( 'callback' => 'twentytwelve_comment', 'style' => 'ol' ) ); ?>
</ol><!-- .commentlist -->
In the functions.php twentytwelve_comment
function the comments are wrapped in a <li></li>
.
在functions.php的secondtwelve_comment函数中,注释包含在
If your comments are on multiple pages or you want to style the numbers you could use a plugin like http://wordpress.org/plugins/gregs-threaded-comment-numbering/. Read here how to use it.
如果您的评论在多个页面上,或者您想要设置数字样式,您可以使用http://wordpress.org/plugins/gregs-threaded-comment-numbering/这样的插件。在这里阅读如何使用它。
#2
0
I was exploring Alexander Kuzmin idea and I think that's how Smashing Magazine is numbering their comments.
我正在探索Alexander Kuzmin的想法,我认为这就是Smashing Magazine如何对他们的评论进行编号。
It's done in a linear fashion without caring if the comment is threaded or not.
如果评论是有线程的话,它是以线性方式完成的,没有关心。
I tested in TwentyEleven, and manipulated the callback for wp_list_comments( array( 'callback' => 'twentyeleven_comment' ) );
.
我在TwentyEleven中测试过,并操纵了wp_list_comments的回调(array('callback'=>'twentyeleven_comment'));.
In functions.php
:
$countcomm = 1;
function twentyeleven_comment( $comment, $args, $depth )
{
global $countcomm;
// PRINT THE COMMENTS AND USE $countcomm TO ECHO THE NEW "COMMENT ID"
// TAKING CARE OF THE COMMENT PERMALINK:
// CHANGE ALL INSTANCES OF comment_ID() AND $comment->comment_ID
// TO $countcomm
$countcomm++;
}
#1
0
Look at the twentytwelve theme. It uses an ordered list.
看看二十世纪的主题。它使用有序列表。
<ol class="commentlist">
<?php wp_list_comments( array( 'callback' => 'twentytwelve_comment', 'style' => 'ol' ) ); ?>
</ol><!-- .commentlist -->
In the functions.php twentytwelve_comment
function the comments are wrapped in a <li></li>
.
在functions.php的secondtwelve_comment函数中,注释包含在
If your comments are on multiple pages or you want to style the numbers you could use a plugin like http://wordpress.org/plugins/gregs-threaded-comment-numbering/. Read here how to use it.
如果您的评论在多个页面上,或者您想要设置数字样式,您可以使用http://wordpress.org/plugins/gregs-threaded-comment-numbering/这样的插件。在这里阅读如何使用它。
#2
0
I was exploring Alexander Kuzmin idea and I think that's how Smashing Magazine is numbering their comments.
我正在探索Alexander Kuzmin的想法,我认为这就是Smashing Magazine如何对他们的评论进行编号。
It's done in a linear fashion without caring if the comment is threaded or not.
如果评论是有线程的话,它是以线性方式完成的,没有关心。
I tested in TwentyEleven, and manipulated the callback for wp_list_comments( array( 'callback' => 'twentyeleven_comment' ) );
.
我在TwentyEleven中测试过,并操纵了wp_list_comments的回调(array('callback'=>'twentyeleven_comment'));.
In functions.php
:
$countcomm = 1;
function twentyeleven_comment( $comment, $args, $depth )
{
global $countcomm;
// PRINT THE COMMENTS AND USE $countcomm TO ECHO THE NEW "COMMENT ID"
// TAKING CARE OF THE COMMENT PERMALINK:
// CHANGE ALL INSTANCES OF comment_ID() AND $comment->comment_ID
// TO $countcomm
$countcomm++;
}