読んだ本や旅のこと、マラソンのことを綴っています。
Wordpressは元々コメントとトラックバックが統合されている。それを無理やり分けて表示する方法をメモしておく。
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);
}
に修正する。
<?php if (get_comments_only_number(‘0′, ‘1′, ‘%’) != ‘0′) { ?>
:
<? } ?>
<?php if (trackpings(‘count’) != ‘(0)’) { ?>
:
<? } ?>
以上。参考までにこのブログのcomments.phpも晒しておくので、参考にしたい方は右クリックで保存からどうぞ。
この記事に対するコメントを残す