I've seen this on several websites, but didn't find any detailed information about how to create this in Drupal. Here is what I'm looking for:

User Posts (x)
User Comments (x)

I need X to be a link to a list of content (posts, comments), posted by specific user. I was looking into using Views, but I don't know how to make linking and display the count of posts/comments.

Any help gratefully received.

Comments

Equ’s picture

*bump*

vertazzar’s picture

joancatala’s picture

I'm also trying to do this... did you find a solution?

Equ’s picture

so far no results...

masood_mj’s picture

I used the views module to show number of comments per user using arguments set to username and selecting summery + number of entries. As a result, it shows a list of users + number of comments for each user. However I want to add users picture there. does anyone know how can I do that?

vertazzar’s picture

it has to have the user picture option when you choose add field feature when you work with views...

i think the thing that you're looking for is placed in PROFILES and USER category.

Equ’s picture

Just found this old issue and decided to write how I solved this (in case if someone needs it).

User Posts (x):

<?php $posts_count=db_result(db_query("SELECT COUNT(nid) FROM {node} WHERE type= 'post' AND uid = %d", arg(1)));
echo('<a href="/user/my/posts">My Posts</a> (<span class="orange">' . $posts_count . '</span>)' ); ?>

User comments (x):

<?php $comment_count=db_result(db_query("SELECT COUNT(cid) FROM {comments} WHERE uid = %d", arg(1)));
echo('<a href="/user/my/comments">My comments</a> (<span class="orange">' . $comment_count . '</span>)' ); ?>

These snippets are used in user-profile.tpl.php

Marko B’s picture

thanx, add this in custom field in views and works great.

jjma’s picture

Interested to know how you did add the custom field?

Jon

Marko B’s picture

views customfiled module :-)

ilya.bezdelev’s picture

In Drupal 7 the syntax is slightly different. Here are snippets for using in your theme or module

function yourmoduleortheme_get_user_posts_count($uid) {
    $query = db_select('node', 'n');
    $query->condition('uid',$uid,'=');
    $query->condition('type','your_desired_content_type','=');
    $query->addExpression('COUNT(nid)', 'posts_count');
    $result = $query->execute();

    if ($record = $result->fetchAssoc())
        return $record['posts_count'];
    
    return 0;
}

function yourmoduleortheme_get_user_comments_count($uid) {
    $query = db_select('comment', 'c');
    $query->condition('uid',$uid,'=');
    $query->addExpression('COUNT(cid)', 'comments_count');
    $result = $query->execute();

    if ($record = $result->fetchAssoc())
        return $record['comments_count'];
    
    return 0;
}
ivars211’s picture

Can you please explain something more about your code? How can I print it out?
I tried to print it with print () function in my user-profile.tpl.php without results.

zil.arman’s picture

1. create 'template.php' file in you theme directory
2. copy above code into this file without '?>' at the end
3. replace 'yourmoduleortheme' with your theme's machine name
4. and then just call those functions in the place you need

Jeroen94’s picture

Am I correct that the snippets you provided aren't compatible with the Rules 7.x-2.5 module? I can't find a data selector like 'user-comments-count' or something similar.

dariogcode’s picture

I use views and views_groupby (http://drupal.org/project/views_groupby) and group by user name, counting nid work like a charm!!!

Drupal experts in Argentina! www.tilon.com.ar