稍微改版

wordpress April 30th, 2009

由於我的 theme 不支援 WordPress 2.7 所以 threaded comments 這個功能一直沒有出現,所以剛剛參考了這篇如何增添 threaded comments 功能把它弄出來了。 :happy: 而目前的設定是 6 層,反正也不會有太多人留言。 :er:

而改完後由於 comments.php 版本跟過去的版本不同,所以沒辦法跟之前一樣的修改,於是透過 Google 我找到這篇如何為WordPress主題增加樓號顯示功能。由於我很弱又很懶,所以就直接把 win7blog 抓下來直接複製貼上 code。

首先在 comment.php 內找到以下兩段程式碼。在

20 <?php if ( have_comments() ) : ?>

加入

21 <?php global $comment_ids; $comment_ids = array();
22 foreach ($comments as $comment)
23 {
24 if (get_comment_type() == "comment")
25 {
26 ++$comment_count;
27 $comment_ids[get_comment_id()] = ++$comment_i;
28 }
29 }
30 ?>

以及在下面程式碼中

29 <?php wp_list_comments(); ?>

增加一些參數,如下所示

39 <?php wp_list_comments('type=comment&callback=win7blog_comment'); ?>

接著是改 functions.php,只要加入

1 // Produces threaded/nested comments structure, requires wordpress 2.7&higher
2 function win7blog_comment($comment, $args, $depth) {
3 $GLOBALS['comment'] = $comment; ?>
4 <li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
5 <div id="div-comment-<?php comment_ID() ?>">
6 <?php $add_below = 'div-comment'; ?>
7 <div class="comment-author vcard"><?php win7blog_commenter_link() ?>
8 <span class="datetime"><?php printf(__(' @ %1$s %2$s','win7blog'), get_comment_date('Y-n-j'), get_comment_time('H:i') );?></span>
9 <span class="reply"><?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'reply_text' => __('Reply', 'win7blog'), 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?></span>
10 </div>
11 <?php comment_text() ?>
12 </div>
13 <?php
14 }
15
16 function win7blog_end_comment() {
17 echo '</li>';
18 }
19 // Produces an avatar image with the hCard-compliant photo class
20 function win7blog_commenter_link() {
21 global $comment_ids;
22 $commenter = get_comment_author_link();
23 if ( ereg( '<a[^>]* class=[^>]+>', $commenter ) ) {
24 $commenter = ereg_replace( '(<a[^>]* class=[\'"]?)', '\\1url ' , $commenter );
25 } else {
26 $commenter = ereg_replace( '(<a )/', '\\1class="url "' , $commenter );
27 }
28 $avatar_email = get_comment_author_email();
29 $avatar_size = apply_filters( 'avatar_size', '40' ); // Available filter: avatar_size
30 $avatar = str_replace( "class='avatar", "class='photo avatar", get_avatar( $avatar_email, $avatar_size ) );
31 if ( $comment_floor = $comment_ids[get_comment_id()] )
32 $comment_floor .= __('','win7blog');
33 echo $avatar . ' <span class="comment_index">' .$comment_floor. '</span><span class="comment_author">' . $commenter . '</span>';
34 }

就可以啦!

最後剛剛才知道原來 Reverse Order in comments 這個功能也內建了。 :palm:

[Settings] → [Disscussion] → [Reverse  Comments should be displayed with the newer(older) comments at the top of each page]

歷史上的今天

Related posts

Tags: , , ,



Leave a Comment