Comments and pingbacks issues

时间:2011-10-16 作者:japanworm

我已经想了很多很多天了。我多次尝试修改代码,总是得到相同的结果。我就是不明白。

我想正确地分离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

请帮我弄清楚。非常感谢!

1 个回复
最合适的回答,由SO网友:japanworm 整理而成

事实上,在尝试了很多之后,我发现它其实很简单,我只是忘记了。

除了注释中的代码之外。php,你也必须在你的单曲中改变这一点。php:

<?php comments_template(); ?>

<?php comments_template(\'\', true); ?>
这就成功了!

我把这个放在这里,供其他可能遇到同样问题的人参考。

结束

相关推荐

使用<fb:Comments-Count>标记显示Facebook评论计数

在Facebook开发者页面上,他们说评论数量可以使用<fb:comments-count href=http://example.com/></fb:comments-count> awesome comments 我将此添加到我的循环中,然后:<fb:comments-count href=<?php the_permalink();?>></fb:comments-count> 显示每篇文章的评论数。即使我有评论,也不会