0

I have a view which displays a list of particular users. For each user displayed I would like to also display the total number of nodes that user has created.

I was wondering if there was an easy and/or efficient way of doing this, or if there is a module available that can? Obviously you would not want to calculate each total on the fly, but rather have the totals cached and updated whenever a user creates/deletes a node.

It would be nice if a module existed that could take care of this aggregate accumulation, and not just for node creation/deletion but for any desired aggregate (per user, or per node, etc).

Any help is greatly appre

0

3 Answers 3

1

If I understand the question this can be done in Views using aggregation.

  1. Set up a View to list All Content (not users). Select Unsorted. Show fields rather than teasers. Wizard settings

  2. Double check you really don't have any sorting in the Sort criteria section. If you do, it'll mess up the aggregation settings. If you forgot, remove it now. I know I'm repeating here, but if you don't do this you run the risk of driving yourself crazy wondering why aggregation doesn't seem to be doing what it's supposed to.

  3. Add the Content: author relationship (in the Advanced section). This is so you can gain access to the the name field for the user.

  4. Add the 'User: name' field (in the Fields section).

  5. Turn on the Use aggregation option (in the Advanced section under Other).

  6. Change the Aggregation settings for the Content: Title field. Set aggregation to COUNT. This will count up all titles authored by the same user.

  7. If you need sorting, e.g. in descending number of posts, you can add that. But make sure under sorts you set the aggregation settings correctly, e.g. to COUNT. Alternatively, leave the Sort criteria section empty and sort via the Table format.

That's the tricky bit. If that's all working you can refine the output with Global: Custom Text fields or use of tables.

Your view configuration will look at bit like this:

Image of basic settings

Image of advanced settings

Note: if you user entity has extra fields, e.g. for a richer user profile or for name variants etc. you may be able to access these through the 'Content: author' relationship. Or you may need to add another relationship.

0

Have a look at Views Calc module.

Views calc combined with a node relationship should get you the results you need.

2
  • Unfortunately I am trying to display an aggregate inside each list item, not an aggregate of the entire list. For example, the list may show ten users, and next to each username I want to show the total nodes that they have created personally.
    – MWay
    Commented Jun 16, 2012 at 3:34
  • That's what views attachments are for. Commented Jun 18, 2012 at 17:30
0

To do this within a User-based view:

  • Add Relation: User: Content authored
  • Set Aggregation: Yes
  • Add Filter: Content NID > 0 and Aggregation Type "Count" (using the above relation)
  • Add Field: User Name
  • Add Field: Content NID and Aggregation Type "Count" (using the above relation)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.