I've got a view that lists users. I would like to be able to say "14 articles" next to a users name who has created 14 nodes of content type "article". I can figure this out with some preprocessing functions, but I was wondering if there was a way to do this sort of thing within Views.

Comments

dawehner’s picture

Did you tryed out adding the user: name field as argument and select summary ?

sammyman’s picture

I want to do this too.

dawehner’s picture

Status: Active » Fixed

Thats a incredible easy one

$view = new view;
$view->name = 'count_nodes';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
$handler->display->display_options['fields']['name']['link_to_user'] = 1;
$handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
/* Argument: User: Name */
$handler->display->display_options['arguments']['name']['id'] = 'name';
$handler->display->display_options['arguments']['name']['table'] = 'users';
$handler->display->display_options['arguments']['name']['field'] = 'name';
$handler->display->display_options['arguments']['name']['default_action'] = 'summary asc';
$handler->display->display_options['arguments']['name']['style_plugin'] = 'default_summary';
$handler->display->display_options['arguments']['name']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['name']['glossary'] = 0;
$handler->display->display_options['arguments']['name']['limit'] = '0';
$handler->display->display_options['arguments']['name']['transform_dash'] = 0;
sammyman’s picture

Thats cool. How do you implement this? Or am I supposed to create a new views with this info? Or can I cut an paste this info somewhere.

Thanks

dagmar’s picture

You can import this view from /admin/build/views/import

mattgilbert’s picture

This is great, thanks! Understanding Views has been quite a challenge for me, and examples like this make all difference. Using a Node view rather than a User view is something I probably never would have thought of, since this is essentially a list of users I'm after.

Is there a way to show not just the number of all posts, but the number of 2 or more types of posts? So something like:

User Name
4 articles
10 blog posts

dawehner’s picture

You could solve this via

  • Write your own argument handler, which is not trivial
  • Wait for a stable version of views3, which does currently this.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.