3

For example, I have a content type with field. The field is select list. The select list has four default values as well as it is required.

I want the output of a view as:

Provincial (2)
Federal (6)
Institutional (3)
...
Value (#)

where # is the number of nodes with this value

How can I accomplish this?

5 Answers 5

2

Assuming Drupal 7 and Views 3:

  1. Create a view based on your content type with a page or block display
  2. Add a contextual filter, based on your select field
  3. Under "When the filter value is NOT available" select "Display a summary"
  4. Configure the summary as you like, with "Display record count with link" enabled

When the filter value is NOT available

0

Use direct database Query, Replace appearance of "field_select" with your field name in below code

SELECT count(*), `field_select_value` FROM `field_data_field_select` GROUP BY `field_select_value`

Then get the label of select field from value using below technique replace field_select with the field name of select list

$key = field_select_value; // Or whatever
$field = field_info_field('field_select');
$label = $field['settings']['allowed_values'][$key];
1
  • Thanks, from your answer, I have to write code to do it, right? If without any coding, can I do this? Actually I can use the same way to get the count on term reference, but not on the select list.
    – lilyyan
    Sep 12, 2012 at 14:22
0

Check this answer https://drupal.stackexchange.com/a/81953/12163 for a similar approach. It uses the views_merge_rows module. No need for custom coding.

The fields of the views will be the Select list field and the nid. The nid will be aggrgated with "Count" and excluded from display. The select list will be overwritten with [select_list] ([nid]).

0

You may use Views Aggregator Plus module to display number of nodes.
After installing and enabling the module, In your view

  • Select table format as Table With Aggregation Options
  • In the settings, under your desired field select Group and Compress as a group aggregation function
  • For the number of nodes, select Count as a group aggregation function for the nodes field
  • Then render the column and add separator as you like for the display
-1

You could use Views Aggregation feature to attain that result. Check https://drupal.stackexchange.com/a/15875/4915 for a solution similar.

2
  • Thanks a lot. I did use the same way as drupal.stackexchange.com/a/15875/4915, however I got the below output: "Provincial (1) Provincial (1)". I want to get "Provincial (2)".
    – lilyyan
    Sep 12, 2012 at 13:39
  • If you've not already it's worth double checking you don't have a dodgy sort setting on your view. If you do have sorts, take them out and see if it works OK. You can put back after if it does and make sure aggregation settings are pukka on the sort fields.
    – Obliquely
    Mar 18, 2013 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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