在Wordpress上仅显示Ping(Pingbacks + Trackbacks)数字

时间:2010-01-24 12:56:13

标签: wordpress count comments trackback pingback

有没有办法在Wordpress上只显示ping计数(数字)?

实际上有comments_number功能但显示评论,pingback和引用的总数。

2 个答案:

答案 0 :(得分:2)

以下代码适用于WordPress 2.9.1。它可能适用于其他版本,但我只针对2.9.1进行了测试。

<?php
global $wpdb;
$post_id = get_the_ID();
$total_ping_count = $wpdb->get_var("SELECT count(comment_id) FROM $wpdb->comments WHERE comment_type = 'pingback'");
$total_approved_pings = $wpdb->get_var("SELECT count(comment_id) FROM $wpdb->comments WHERE comment_type = 'pingback' and comment_approved = 1");
$post_ping_count = $wpdb->get_var("SELECT count(comment_id) FROM $wpdb->comments WHERE comment_type = 'pingback' and comment_approved = 1 and comment_post_id = $post_id");
echo "The total number of pings on this site is $total_ping_count.\n";
echo "The total number of approved pings on this site is $total_approved_pings.\n";
echo "The total number of approved pings on this post is $post_ping_count.\n";
?>

上面的代码仅为pingback提供了计数。如果您想要引用而不是pingback,只需将comment_type = 'pingback'更改为comment_type = 'trackback',或者如果您想要合并计数,请将其更改为comment_type IN ('pingback', 'trackback')

答案 1 :(得分:0)

不完全确定你想要什么:只显示pingbacks?如果是这样,我还没有尝试过,但是Template Tags/wp list comments « WordPress Codex显示列出了pingback和选项。