Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Apress.Pro.Drupal.7.Development.3rd.Edition.Dec.2010.pdf
Скачиваний:
74
Добавлен:
14.03.2016
Размер:
13 Мб
Скачать
☆

CHAPTER 15 ■ WORKING WITH TAXONOMY

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 will be 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

■ Tip Use the path module to set friendly URL aliases for the taxonomy URLs you use so they won’t have all those scary numbers at the end.

Specifying Depth for Hierarchical Vocabularies

In the previous examples, we’ve been using an implied parameter. For example, the URL

http://example.com/?q=taxonomy/term/5

is really

http://example.com/?q=taxonomy/term/5/0

where the trailing 0 is the number of levels of hierarchy to search when preparing the result set for display; all would designate that all levels should be included. Suppose you had the hierarchical vocabulary shown in Table 15-3.

349

Download from Wow! eBook <www.wowebook.com>

CHAPTER 15 ■ WORKING WITH TAXONOMY

Table 15-3. A Geographical Hierarchical Vocabulary (Child Terms Are Indented Below Their Parent)

Term ID

Name

1 C

anada

2

British Columbia

3

Vancouver

4

Ontario

5

Toronto

The first level of hierarchy is the country, Canada; it has two children, the provinces British Columbia and Ontario. Each province has one child, a major Canadian city where Drupal development is rampant. Here’s the effect of changing the depth parameter of the URL.

All nodes tagged with Vancouver will share the following URL:

http://example.com?q=taxonomy/term/3 or http://example.com?q=taxonomy/term/3/0

To display all nodes tagged with British Columbia (but none tagged with Vancouver), use this URL:

http://example.com?q=taxonomy/term/2

The following URL applies to all nodes tagged with British Columbia and any British Columbian city (note that we’re setting the depth to one level of hierarchy):

http://example.com?q=taxonomy/term/2/1

■ Note The result set is displayed as a regular node listing. If you want to have the node titles and/or teasers displayed hierarchically, you’d need to write a custom theme function that does this or use the views module (http://drupal.org/project/views).

Automatic RSS Feeds

Each term has an automatic RSS feed that displays the latest nodes tagged with that term. For example, the feed for term ID 3 is at

http://example.com/?q=taxonomy/term/3/feed

350

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]