问题
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:
You should be able to do the grouping simply within views. No need to touch the template.
Here's how to group:
- 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
- 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...
- Select the field that you now have in your view (even though you're not showing it) as your grouping field!
That should be it! Let us know if it works for you.
来源:https://stackoverflow.com/questions/13828952/drupal-7-views-list-group-by-field