Tags, collections and sections
5 February 2018 | 27 views | Tags: Documentation
Tags are essentially "subject labels" that you can apply to other content objects; you can label a content object with as many tags as you want. Associations between tags and content are recorded in the taglink table of the database. Every time a content object is inserted, updated or deleted its associated taglinks are updated automatically, so long as you do this using the insert(), delete() and update() methods in the relevant content handler. Taglinks are represented by the TfishTaglink class.
Collections basically function as categories, but they are fully-fledged content objects in their own right. You can assign content to any existing collection using the 'parent' field in the content data entry form. Any kind of content can be assigned to a collection, so mixed sets of content are possible. Collections can be nested by assigning one as the parent of another, thereby creating subcategories.
Tags can also be organised into collections, which is useful if you want to create custom tag select boxes from a subset of tags. To retrieve a collection of tags and build a select box with it call TfishTagHandler::getArbitrarySelectBox():
/** * Prepare a select box from an arbritrary collection of tags. */ // Retrieve tags that are members of a collection with ID 851 (online tags only). $criteria = new TfishCriteria(); $criteria->add(new TfishCriteriaItem('parent', 851); $criteria->add(new TfishCriteriaItem('type', 'TfishTag')); $criteria->add(new TfishCriteriaItem('online', 1)); $tag_list = TfishTagHandler::getList($criteria); // Prepare the select box using the retrieved tags. Target will be present page (index.php). $tfish_template->select_action = 'index.php'; $tfish_template->select_filters = TfishTagHandler::getArbitraryTagSelectBox($clean_tag, $tag_list); $tfish_template->select_filters_form = $tfish_template->render('select_filters');
Both tags and collections can be used to quickly create sections for a website. By 'section' I mean a logical division of content, perhaps by content type or by subject, that you might include as menu or navigation element.
If you wanted to create a "Publications" section on your website consisting of (say) PDF downloads, you could:
- Create a collection object called "Publications". Both tags and collections display a list of member / child content below their own description, in teaser format.
- Edit the relevant download objects, setting "Publications" as their parent.
- Add a link to the ID of the "Publications" collection in your navigation menu (remember it's as simple as https://yoursite.com?id=42).
- If you would prefer a custom, user-friendly URL such as 'publications.php', that can be achieved by making a copy of /extras/staticpage.php with whatever filename you prefer. Editing the tag or collection ID into the configuration section at the top of the script. Put it in your site root and you are done.
////////// CONFIGURATION ////////// // 1. Enter the ID of the content object you want to display on this page, eg. 10. $id = 10; // 2. Enter the name of the page you want headings and tags to link back to, without extension, eg. 'index'. $target_file_name = 'index'; $tfish_template->target_file_name = $target_file_name; // 3. Set the page title to whatever you like. $tfish_template->page_title = 'Some page title'; ////////// END CONFIGURATION //////////
Your new section will automatically update itself as you add new content to the Publications collection. Tags work the same way. Static pages with custom URLs also also make good sections, However, you can use any content object.
Copyright, all rights reserved.
This guide will give you an overview of the architecture of Tuskfish CMS, how to write code to perform common operations and how to extend the system to suit yourself. The guide accompanies the Tuskfish API documentation. Keep a copy handy as you read this guide. It is best to review links to the API where provided, as not every detail will be discussed in the text. This is the first version of the guide, so it is still a work in progress.