有没有办法在 Wordpress 上只显示 ping 计数(数字)?
实际上有comments_number
功能,但显示评论、pingbacks 和 trackbacks 的总数。
以下代码适用于 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')
.
不完全确定你想要什么:只显示 pingbacks?如果是这样,我还没有尝试过,但是模板标签/wp 列表评论 « WordPress Codex显示列表 pingbacks 和选项。