Organising content with tags and collections
15 December 2017 | 361 views
Tags and collections are tools for grouping related content. They can be used to filter the contents of your home page or to create sections within your website.
The tagging system
Tags are essentially subject labels that you can apply to content. You can apply as many tags to a content item as you want. Visitors can use the tag select box on the home page to filter your site by subject. When an individual content item is viewed it will display a list of its tags, which will direct visitors to related content.
Tags are created with the standard content entry form by selecting 'Tag' as the content type. Once a tag is created it will appear as an option in the ‘tag’ section of the form when entering new content, and as an option in the tag select box on your home page (once you have tagged something with it, as empty tags are not displayed).
Tags are important content items in their own right and represent a logical ‘section’ in your site (see below), so it is good practice to provide them with a nice teaser, description and image. They are returned in search results and can be viewed as a single object, in which case they will display a list of related content teasers below the tag description.
Excluding tags from the tag select box
The tag select box is a primary navigation element for your site. If you add a lot of tags you may find that the drop down list becomes cluttered and unwieldy. You may not want to have every tag included in it. To exclude a tag from the public (front end) select box simply mark as 'offline'. It will still be present and fully available on your site, but it will no longer appear in the select box. "Offline" tags are still displayed when an individual content item is viewed, and on the administrative back end tag select box.
Collections represent a group of related content, for example an album of music would make a good collection object and its members would be individual soundtracks (ie. audio content items that you uploaded separately). However, collections can contain a mixture of items - you can have text articles, audio and video files, imeges etc. all within a single collection.
Collections are created through the standard content entry form by selecting ‘collection’ as the content type. Once created a collection becomes available as an option in the ‘Parent’ section of the form. Other content items can be assigned to the collection by choosing it as their parent.
When the full description of a collection is viewed its member content items are displayed below it as a list of teasers. A member item that is viewed will also display a link back to its parent collection.
Collections can be nested, ie. one collection can be a member of another. In this way collections can function something like categories and sub-categories, although they are independent content items in their own right.
Creating custom tag select boxes
One useful application of collections is to use them to group related tags. Simply create a collection object and then edit each relevant tag, assigning that collection as their parent. For example, if you wanted a list of tags for different countries, you could create a 'Countries' collection and assign all your country tags to it.
Tag collections can be used to create customised select boxes, displaying only tags from a particular collection. If you would like to replace the default ‘global’ tag select box, you can do that by building it with a different method, getArbitraryTagSelectBox(). Basically you can prepare a tag list using any means you prefer and pass it in. For example, you could set criteria to select tags that have a particular collection as their parent,
// Retrieve tags that are members of collection with ID 20. $criteria = $tfCriteriaFactory->getCriteria(); $criteria->add($tfCriteriaFactory->getItem('type', 'TfishTag')); // Only select tags. $criteria->add($tfCriteriaFactory->getItem('parent', 20); // Members of collection 20. $criteria->add($tfCriteriaFactory->getItem('online', 1)); // Online tags only. $tagList = $tagHandler->getListOfTitles($criteria); // Retrieves ID => title as key => value. // Prepare tag select box and assign to template. $tagHandler = $contentFactory->getContentHandler('tag'); $tfTemplate->selectAction = 'index.php'; $tfTemplate->selectFilters = $tagHandler->getArbitraryTagSelectBox(null, array $tagList); $tfTemplate->selectFiltersForm = $tfTemplate->render('selectFilters');
You can also restrict the select box to return tags in use by a certain content type, by passing in the name of the content subclass as a second parameter:
// Select box including only tags actually used by article objects. $tfTemplate->selectFilters = $tagHandler->getTagSelectBox($cleanTag, 'content', 'TfArticle');
Copyright, all rights reserved.