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

有没有办法在Wordpress上只显示ping计数(数字)? 实际上有
comments_number
功能,但显示评论,pingback和引用的总数。     
已邀请:
以下代码适用于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和选项。     

要回复问题请先登录注册