Drupal 7 Views - list group by field

2019-02-18 21:08发布

I have a View that list content of type Bio (the biographies of people). However, I would like to format it so that they are grouped under different headings.

I added a new field to the Bios content type which is a dropdown list with three different options - Foo, Bar and Baz. What I want to do is display the people under the heading of their respective group.

Currently:

- John Doe
- Jane Doe
- Jack Doe
- Juanita Doe
- Jim Doe

What I want:

#Foo
- John Doe
- Jane Doe

#Bar
- Jack Doe
- Juanita Doe

#Baz
- Jim Doe

1条回答
乱世女痞
2楼-- · 2019-02-18 21:30

You should be able to do the grouping simply within views. No need to touch the template.

Here's how to group:

  1. Add the field that's the drop down to your list of fields in your view. If you don't want to display it with each person though (just want to display it at the top), make sure you select 'Exclude from display' when you're setting up the field
  2. Click to configure the settings of your view's format. I'm using 'Unformatted list' in my example, but this could be an html list or a table...

enter image description here

  1. Select the field that you now have in your view (even though you're not showing it) as your grouping field!

enter image description here

That should be it! Let us know if it works for you.

查看更多
登录 后发表回答