我已经想了很多很多天了。我多次尝试修改代码,总是得到相同的结果。我就是不明白。
我想正确地分离pingback和注释,这是我使用以下代码所做的:
<?php if ( have_comments() ) : ?>
<h2 class="h2comments"><img src="http://zoomingjapan.com/wp-content/themes/alltuts-child/images/comments_big.png" /><?php comments_number(\'No Comments\', \'1 Comment\', \'% Comments\' );?> <a href="#respond" class="addComment"><img src="http://zoomingjapan.com/wp-content/themes/alltuts/images/add_your_coment_ver2.png" border="0"></a></h2>
<ul class="commentlist">
<?php wp_list_comments(array(
\'callback\'=>\'mytheme_comment\',
\'type\'=>\'comment\',
)); ?>
<div class="navigation">
<?php paginate_comments_links(); ?>
</div>
</ul>
<?php else : // this is displayed if there are no comments so far ?>
<?php if (\'open\' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<!-- If comments are closed. -->
<p class="nocomments">Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
<?php if ( have_comments() ) : ?>
<ul class="pingbacks"><h2>Pingbacks</h2>
<?php wp_list_comments(array(
\'callback\'=>\'mytheme_comment\',
\'type\'=>\'pings\',
)); ?>
</ul>
<?php else : // this is displayed if there are no comments so far ?>
<?php if (\'open\' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<!-- If comments are closed. -->
<p class="nocomments">Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
然而,即使没有可显示的pingback,pingback(标题和所有内容)仍然会显示出来。
我试着把它改成这样:
<?php if ( have_comments() ) : ?>
<?php if ( ! empty($comments_by_type[\'comment\']) ) : ?>
<h2 class="h2comments"><img src="http://zoomingjapan.com/wp-content/themes/alltuts-child/images/comments_big.png" /><?php comments_number(\'No Comments\', \'1 Comment\', \'% Comments\' );?> <a href="#respond" class="addComment"><img src="http://zoomingjapan.com/wp-content/themes/alltuts/images/add_your_coment_ver2.png" border="0"></a></h2>
<ul class="commentlist">
<?php wp_list_comments(\'type=comment&callback=mytheme_comment\'); ?>
</ul>
<?php endif; ?>
<?php if ( ! empty($comments_by_type[\'pings\']) ) : ?>
<h2 id="pings">Trackbacks/Pingbacks</h2>
<ul class="commentlist">
<?php wp_list_comments(\'type=pings\'); ?>
</ul>
<?php endif; ?>
<div class="navigation">
<?php paginate_comments_links(); ?>
</div>
<?php else : // this is displayed if there are no comments so far ?>
<?php if (\'open\' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<!-- If comments are closed. -->
<p class="nocomments">Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
但是,现在,除非我去掉“if empty”命令,否则不会显示pingback和注释。如果我这样做了,那么即使没有pingback,pingback标题也会再次出现。这快把我逼疯了!也许这与回调函数有关?
下面是我调用的函数:
function mytheme_comment($comment, $args, $depth) {
$GLOBALS[\'comment\'] = $comment; ?>
<li <?php comment_class(\'clearfix\'); ?> id="li-comment-<?php comment_ID() ?>">
<?php echo get_avatar($comment,$size=\'63\'); ?>
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-meta commentmetadata clearfix">
<?php printf(__(\'<strong>%s</strong>\'), get_comment_author_link()) ?><?php edit_comment_link(__(\'<img src="http://www.zoomingjapan.com/wp-content/themes/alltuts/images/edit.gif">\'),\' \',\'\') ?> <span><?php printf(__(\'%1$s @ %2$s\'), get_comment_date(\'Y/n/j\'), get_comment_time(\'G:i\')) ?>
</span>
<div class="text">
<?php comment_text() ?>
</div>
</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="reply">
<?php comment_reply_link(array_merge( $args, array(\'depth\' => $depth, \'max_depth\' => $args[\'max_depth\']))) ?>
</div>
</div>
<?php }
[这里是]我网站的一个示例页面,包含评论和pingback。
1请帮我弄清楚。非常感谢!