Drupal contents can be classified by a hierarchical structure of terms: a single content can be associated to one or more terms and each term can have an associated web page where all the related contents are shown. The aspect of this page can be configured in a detailed way. In this example we will use this feature to show contents to visitor.
The first thing to do is the creation of a dictionary for our terms. This can be done by accessing to the "Taxonomy" menu, in the "Structure" section.
Now we have to define the aspect of the web pages for our categories, defining a view for our taxonomy terms. Views was an additional module in Drupal 7, but in version 8 it is integrated into the core distribution. "Views" are what Drupal uses to organize the display of collection of items.
We find the "View" page definition in the "structure" section, as shown in the figure below. The page has a long list of views, only the first entries being shown in the figure. Drupal use views internally for everything and all can be configured, here we click on the "edit" button of the view for taxonomy terms (not shown in the picture).
At right top there is a button to edit the name and the description of the view, but we maintain the defaults.
Then we have a TITLE option: the title can be used as a page header, depending on the theme.
The FORMAT option defines how the collection is organized: clicking on the name after "Format" ("Grid" in the figure), we see a menu:
.mediumbox {
width: 250px ;
height: 400px ;
float: left ;
background-color: white ;
text-align: left ;
padding: 0.5em ;
margin: 0.1em ;
border-style: solid;
border-width: 1px;
border-color: #aaaaaa;
overflow: hidden ;
}
We have to insert this class into the theme; how it is done depend somewhat on the theme used:
many themes allow for adding user defined CSS specifications.
We use the "danland" theme and we have to edit the
"danland.libraries.yml" file in the main folder of the theme, to "un-comment"
the line: "#css/local.css: {}", then we can insert our class in the "local.css" file.
Under "FORMAT" there is the the "Show" option which defines how the items are shown, we can have: "content", "fields" or "search results", each options can be further configured: the content can be shown entirely or as a "teaser" (a summary) or in other ways; "fields" allows for displaying only chosen fields; "search results" list items using the view for the search results.
The "FIELD" option is used to choose the fields to be shown, when we use a "list type" format.
"FILTER CRITERIA" allow for deciding which items are shown, here we show only items in the "published" status and for the current language;
"SORT CRITERIA" defines the sorting of items; items with the "sticky" flag will be shown first, then the items are ordered by an "Ordering" field, then by date (more recent before). The ordering field is a custom field we will add to the "page" content type. We will show below how this is done.
"PAGE SETTINGS": here we can define an URL path for taxonomy terms (but we have defined an URL alias for each one); we can choose if terms are inserted in menus; and define some access criteria: we could restrict access to specific user roles, but here everyone having permission to see published contents will see the dictionary term pages.
The "HEADER" and "FOOTER" can be used to add text before or after the shown item collection.
The "NO RESULT BEHAVIOR" is an option to use a special text when there are no items to show
"PAGER" divides the shown items in multiple pages; we put here 10 items per page.
Under the "advanced" section there are less used options, which we will not cover here: we will accept the default settings.
Views are very customizable, resulting in a lot of options not always easy to understand.
You have to experiment to find the best ones for your web site, but often the defaults
are enough.