有没有按作者统计帖子的插件?

时间:2011-03-31 作者:evergreen

我想有一个页面列出所有作者和他们每个人发表的帖子数量。有没有插件可以做到这一点?能够计算评论的数量也将是一个加号。

谢谢你的帮助。

1 个回复
SO网友:Philip

我不知道插件,但你可以使用它:

作者。php您可以使用它来统计帖子:

<?php
global $wp_query;
$curauth = $wp_query->get_queried_object();
$post_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = \'" . $curauth->ID . "\' AND post_type = \'post\' AND post_status = \'publish\'");
?>
<h2>Post Count: <?php echo $post_count; ?></h2>
在循环中,您可以使用此选项统计帖子和评论:

<?php
global $wpdb;
$user_id = $post->post_author;  //change this if not in a std post loop
$where = \'WHERE comment_approved = 1 AND user_id = \' . $user_id ;
$comment_count = $wpdb->get_var(
    "SELECT COUNT( * ) AS total
        FROM {$wpdb->comments}
        {$where}
    ");
$user = get_userdata($user_id);
$post_count = get_usernumposts($user->ID);
echo \'<p>User \' . $user->display_name . \' post count is \' . $post_count .\', comment count is \' . $comment_count . \'</p>\';
?>
对于所有作者:

<?php
global $wpdb;
$where = \'WHERE comment_approved = 1 AND user_id <> 0\';
$comment_counts = (array) $wpdb->get_results("
        SELECT user_id, COUNT( * ) AS total
        FROM {$wpdb->comments}
        {$where}
        GROUP BY user_id
    ", object);
foreach ( $comment_counts as $count ) {
  $user = get_userdata($count->user_id);
  $post_count = get_usernumposts($user->ID);
  echo \'<p>User \' . $user->display_name . \' post count is \' . $post_count .\', comment count is \' . $count->total . \'</p>\';
}
?>

相关推荐

有没有按作者统计帖子的插件? - 小码农CODE - 行之有效找到问题解决它

有没有按作者统计帖子的插件?

时间:2011-03-31 作者:evergreen

我想有一个页面列出所有作者和他们每个人发表的帖子数量。有没有插件可以做到这一点?能够计算评论的数量也将是一个加号。

谢谢你的帮助。

1 个回复
SO网友:Philip

我不知道插件,但你可以使用它:

作者。php您可以使用它来统计帖子:

<?php
global $wp_query;
$curauth = $wp_query->get_queried_object();
$post_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = \'" . $curauth->ID . "\' AND post_type = \'post\' AND post_status = \'publish\'");
?>
<h2>Post Count: <?php echo $post_count; ?></h2>
在循环中,您可以使用此选项统计帖子和评论:

<?php
global $wpdb;
$user_id = $post->post_author;  //change this if not in a std post loop
$where = \'WHERE comment_approved = 1 AND user_id = \' . $user_id ;
$comment_count = $wpdb->get_var(
    "SELECT COUNT( * ) AS total
        FROM {$wpdb->comments}
        {$where}
    ");
$user = get_userdata($user_id);
$post_count = get_usernumposts($user->ID);
echo \'<p>User \' . $user->display_name . \' post count is \' . $post_count .\', comment count is \' . $comment_count . \'</p>\';
?>
对于所有作者:

<?php
global $wpdb;
$where = \'WHERE comment_approved = 1 AND user_id <> 0\';
$comment_counts = (array) $wpdb->get_results("
        SELECT user_id, COUNT( * ) AS total
        FROM {$wpdb->comments}
        {$where}
        GROUP BY user_id
    ", object);
foreach ( $comment_counts as $count ) {
  $user = get_userdata($count->user_id);
  $post_count = get_usernumposts($user->ID);
  echo \'<p>User \' . $user->display_name . \' post count is \' . $post_count .\', comment count is \' . $count->total . \'</p>\';
}
?>

相关推荐