|
WordPressは元々コメントとトラックバックが統合されている。それを無理やり分けて表示する方法をメモしておく。
- Trackping Separatorプラグインを導入
- http://ja.forums.wordpress.org/topic/861の6件目のコメントで紹介されているcomments.phpのソースを自分流にアレンジする
- trackpings.phpの修正。
function get_comment_only_number() {
global $wpdb, $tablecomments, $post;
$comments = $wpdb->get_results(“SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post->ID AND
comment_type NOT REGEXP ‘^(trackback|pingback)$’ AND comment_approved = ’1′”);
$cnt = count($comments);
return $cnt;
}
を
function get_comment_only_number() {
global $wpdb, $tablecomments, $post;
$comments = $wpdb->get_results(“SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post->ID AND
comment_type NOT REGEXP ‘^(trackback|pingback)$’ AND comment_approved = ’1′”);
$cnt = count($comments);
return $cnt;
}
function get_comments_only_number($no=”, $one=”, $many=”) {
global $wpdb, $tablecomments, $post;
$comments = $wpdb->get_results(“SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post->ID AND comment_type = ” AND comment_approved = ’1′”);
$cnt = count($comments);
if (!$cnt)
return $no;
elseif ($cnt == 1)
return $one;
else
return str_replace(“%”, $cnt, $many);
}
に修正する。
- comments.phpのコメントとトラックバックを表示させている部分を以下のコードで挟む
<?php if (get_comments_only_number(’0′, ’1′, ‘%’) != ’0′) { ?>
:
<? } ?>
<?php if (trackpings(‘count’) != ‘(0)’) { ?>
:
<? } ?>
以上。参考までにこのブログのcomments.phpも晒しておくので、参考にしたい方は右クリックで保存からどうぞ。
参考URL
関連する記事
|