Taxonomy consists of two primary elements, vocabularies and terms. I often think of vocabularies as a container for a set ofwords or phrases that are related. For example, I might create a vocabulary named professional sports, and with in that
vocabulary I might create words or phrases such as football, basketball, hockey, cricket, rugby, and golf. Each word or
phrase is a term. After creating the vocabulary and associated terms, I can then create a field on the content type(s) that
I want.
Creating a Vocabulary
To create a vocabulary, navigate to Structure -> Taxonomy and click the “Add vocabulary” link.
The form for creating a vocabulary consists of a Name and Description field. Simply enter the name of the vocabulary and optionally a description, and then click Save.
Creating Terms
To create terms, navigate to Structure -> Taxonomy and click the add terms link for the selected vocabulary.
On the create terms page, enter the Name of the term (e.g., basketball) and optionally a description and URL alias. By
default the URL used to access all content associated with a taxonomy term is structured as taxonomy/term/9. You may
want to use the URL alias field to create a more user- friendly such as professional sports/basketball.
Assigning a Vocabulary to a Content Type
Taxonomy vocabularies are assigned to content types so that authors can select or enter terms to associate with the piece of content they are creating. Taxonomy vocabularies are assigned to content types as a field. To associate a vocabulary
with a content type,navigate to Structure -> Content types and click the manage fields link for the content type that you
want to add the vocabulary to. Figure 15-1 shows the interface for creating a new field that is of the type Term
reference, which is the field type as sociated with taxonomy.
The next step in the process is to select the taxonomy vocabulary that the field is associated with. The next screen in the process is a simple select list where you pick the vocabulary you wish to use. Select the vocabulary and click the “Save
field settings” button. The final step in the process of creating a taxonomy-based field is to specify whether the field is
required, meaning the author must select one or more terms, the help text that will be displayed below the list of terms,
the default value that should be selected when the content creation form is displayed, and the number of values that an
author can select. Figure 15-2 shows the options that may be set on this last screen in the taxonomy field creation
process.
After saving the field, the content creation form will now include a new field where the author can select from the list
of terms associated with the vocabulary.
Kinds of Taxonomy
There are several kinds of taxonomy. The simplest is a list of terms, and the most complex has multiple hierarchical
relationships. Additionally, terms may be synonyms of or related to other terms. Let’s start with the simplest first.
Flat
A vocabulary that consists of only a list of terms is straightforward. Table 15-1 shows how you can classify some
programming languages in a simple, flat vocabulary that we’ll call Programming Languages.
Hierarchical
Now, let’s introduce the concept of hierarchy, where each term may have a relationship to another term; see Table 15-2.
Figure 15-3 shows the hierarchical relationships explicitly.
In this example, Procedural is a parent and Cobol is a child. Notice that each term has its own ID, no matter whether it’sa parent or a child.
You can arrange terms into hierarchies when the term is created by selecting a parent term from the Parent field in the
“Advanced options” section of the “Add term” form or by using drag and drop to position terms. After more than one
term has been added,the drag-and-drop interface becomes available at Administer -> Content management -> Taxonomy
by clicking the “list terms” link for the vocabulary you are working with. The drag-and-drop interface is shown in
Figure 15-4.
Figure 15-1. The form for adding a vocabulary to a content type
The next step in the process is to select the taxonomy vocabulary that the field is associated with. The next screen in the process is a simple select list where you pick the vocabulary you wish to use. Select the vocabulary and click the “Save
field settings” button. The final step in the process of creating a taxonomy-based field is to specify whether the field is
required, meaning the author must select one or more terms, the help text that will be displayed below the list of terms,
the default value that should be selected when the content creation form is displayed, and the number of values that an
author can select. Figure 15-2 shows the options that may be set on this last screen in the taxonomy field creation
process.
Figure 15-2. Configuration options for the new taxonomy field
After saving the field, the content creation form will now include a new field where the author can select from the list
of terms associated with the vocabulary.
Kinds of Taxonomy
There are several kinds of taxonomy. The simplest is a list of terms, and the most complex has multiple hierarchical
relationships. Additionally, terms may be synonyms of or related to other terms. Let’s start with the simplest first.
Flat
A vocabulary that consists of only a list of terms is straightforward. Table 15-1 shows how you can classify some
programming languages in a simple, flat vocabulary that we’ll call Programming Languages.
Table 15-1. Simple Terms in a Vocabulary
| |
Term ID
|
Term Name
|
1
|
C
|
2
|
C ++
|
3
|
Cobol
|
Hierarchical
Now, let’s introduce the concept of hierarchy, where each term may have a relationship to another term; see Table 15-2.
Table 15-2. Hierarchical Terms in a Vocabulary
(Child Terms Are Indented Below Their Parent)
|
|
Term ID
|
Term Name
|
1
|
Object-Oriented
|
2
|
C ++
|
3
|
Smalltalk
|
4
|
Procedural
|
5
|
C
|
6
|
Cobol
|
Figure 15-3 shows the hierarchical relationships explicitly.
In this example, Procedural is a parent and Cobol is a child. Notice that each term has its own ID, no matter whether it’sa parent or a child.
Figure 15-3. A hierarchical vocabulary has parent-child relationships between terms.
You can arrange terms into hierarchies when the term is created by selecting a parent term from the Parent field in the
“Advanced options” section of the “Add term” form or by using drag and drop to position terms. After more than one
term has been added,the drag-and-drop interface becomes available at Administer -> Content management -> Taxonomy
by clicking the “list terms” link for the vocabulary you are working with. The drag-and-drop interface is shown in
Figure 15-4.
Figure 15-4. Terms can be arranged into a hierarchy using the drag-and-drop interface.
Multiple Hierarchical
A vocabulary may have multiple hierarchies instead of a single hierarchy. This simply means that a term may
have more than one parent. For example, suppose you add PHP to your vocabulary of programming languages.
PHP can be written procedurally, but in recent versions, object-oriented capabilities have been introduced. Should you classify it under Object-Oriented or Procedural? With multiple hierarchical relationships, you can
do both, as shown in Figure 15-5.
Figure 15-5. In a multiple hierarchical vocabulary, terms can have more than one parent.
It’s worthwhile to spend a significant amount of time thinking through use cases for taxonomy when in the
planning stage of a web site to determine what kind of vocabulary you need. Because a multiple hierarchy
vocabulary cannot easily be shown in a user interface, Drupal warns you that the drag-and-drop interface
(shown in Figure 15-4) will be disabled if you select multiple parents for a term. The warning is shown in
Figure 15-6.
Figure 15-6. Selecting multiple parents for a term will disable the drag-and-drop interface.
Viewing Content by Term
You can always view the nodes associated with a given term by going to the term’s URL, unless a module has overridden this view. For example, in http://example.com/?q=taxonomy/term/5, the 5 is the term ID of the
term you wish to view. The result willbe a list containing titles and teasers of each node tagged with that term.
Using AND and OR in URLs
The syntax for constructing taxonomy URLs supports AND and OR by use of the comma (,) and plus sign (+) characters, respectively. Some examples follow. To show all nodes that have been assigned term IDs 5 and 6, use
the following URL:
http://example.com/?q=taxonomy/term/5,6
Use the following URL to show all nodes that have been assigned term IDs 1, 2, or 3:
http://example.com/?q=taxonomy/term/1+2+3
Không có nhận xét nào:
Đăng nhận xét