2013-08-18 98 views
1

我已經看到了各種網站使用內置的wordpress評論系統與自定義回調(生成自己的html不同,如果內置評論在WordPress中)添加數字評論在他們的網站。在wordpress中給評論添加數字

阿拉 - http://mobile.smashingmagazine.com/2013/08/12/creating-high-performance-mobile-websites/

每個註釋旁邊都有一個編號。 經過大量的搜索後,我找不到任何內置的wordpress功能。

我爲我的評論使用自定義回調。

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 
     } 

任何人都可以給我任何想法如何編號每個評論?

+0

不能你一個$ GLOBALS名爲$算什麼,你算你印多少評論? –

回答

0

看看第二十二個主題。它使用有序列表。

<ol class="commentlist"> 
    <?php wp_list_comments(array('callback' => 'twentytwelve_comment', 'style' => 'ol')); ?> 
</ol><!-- .commentlist --> 

在的functions.php twentytwelve_comment功能註釋包裝在一個<li></li>

如果您的評論是在多個頁面上,或者您想對數字進行樣式設置,您可以使用像http://wordpress.org/plugins/gregs-threaded-comment-numbering/這樣的插件。閱讀here如何使用它。

+0

我也使用一個有序列表,問題是當使用線程註釋時,子元素(註釋)是ul的。如果可能的話,我寧願不使用插件。 – andy

0

我正在探索Alexander Kuzmin的想法,我認爲這就是Smashing Magazine爲他們的評論編排的方式。

這是以線性方式完成的,而不關心評論是否有線索。

我在TwentyEleven進行了測試,並操縱了wp_list_comments(array('callback' => 'twentyeleven_comment'));的回調。

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++; 
}