2010-01-24 5 views

Répondre

2

Le code suivant fonctionne sur WordPress 2.9.1. Cela peut fonctionner sur d'autres versions, mais je l'ai seulement testé contre 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"; 
?> 

Le code ci-dessus donne des comptes uniquement pour les pingbacks. Si vous voulez trackbacks au lieu de pingbacks simplement changer comment_type = 'pingback' à comment_type = 'trackback' ou si vous voulez un compte combiné le changer en comment_type IN ('pingback', 'trackback').

+0

Merci beaucoup. Je vais essayer. – fatihturan

Questions connexes