Tags Class
Post Tagging & Taxonomy Class
The Tags class is a specialized extension of the GeniXCMS taxonomy system. While it leverages the underlying table structure of the Categories class, it provides specific logic for managing flat descriptors (Tags), batch parsing, existence checks, and the dynamic generation of "Tag Cloud" UI components for your themes.
⚡ Data Manipulation
Tags::add(string $tags_list)
Parses and commits a collection of tag entities to the database from a comma-separated string.
- De-duplication: Checks existence with
Tags::exist()before performing anINSERT. - Slug Generation: Auto-generates a URL slug via
Typo::slugify(). - Type Assignment: All entries are automatically assigned
type = 'tag'in thecattable.
// Batch insert newly discovered tags
Tags::add("industrial, premium, latte, vite");
Tags::exist(string $tag)
Checks if a tag already exists in the database (by name or slug). Returns true or false.
Tags::delete(int $tag_id)
Permanently removes a tag and its associated metadata from the system.
🔍 Search
Tags::search(string $q)
Returns an array of tag objects matching a partial name query (used for autocomplete). Results are limited to 10.
// Used by the AJAX tag autocomplete endpoint
$results = Tags::search('ph'); // Returns matches like 'php', 'phpunit'
Tags::count(string $tag)
Returns the number of posts associated with a specific tag name.
🎨 UI & Presentation Logic
Tags::cloud()
Generates a semantic HTML Tag Cloud suitable for theme sidebars or footer widgets.
- Process: Fetches all entities of type
tag, calculates the frequency of each usingTags::count(), sorts by frequency descending, and returns linked items. - Output: Anchor tags with
.tag-itemclass and post count in.tag-countspan.
{* In your theme sidebar *}
<div class="widget tag-cloud">
{Tags::cloud()|noescape}
</div>
🏗️ Technical Architecture & Wrapper Methods
The Tags class acts as a high-level wrapper for several Categories Class utilities, pre-configured for the tag context.
| Method | Role | Logic |
|---|---|---|
dropdown($vars) |
Selection UI | Generates a <select> list of all active tags. |
lists($vars) |
Collection | Returns a raw array of all tag objects. |
name($id) |
Identity | Resolves the plain-text name for a specific tag ID. |
slug($id) |
Routing | Returns the SEO-friendly URL slug for the tag. |
id($name) |
Lookup | Returns the database ID for a given tag name. |
type($id) |
Metadata | Returns the type field value for a given ID. |
getParent($id) |
Hierarchy | Returns parent data (always 0 for flat tags). |
📂 Database Schema
Tags are stored in the core cat table, distinguished by the type field value set to 'tag'. This unified architecture allows tags to benefit from the same slug-generation and URL routing as standard categories.
| Column | Value for Tags |
|---|---|
name |
The display label (e.g., PHP) |
slug |
URL-safe version (e.g., php) |
parent |
Always 0 (flat, no hierarchy) |
type |
Always 'tag' |
See Also
- Categories Class — The underlying taxonomy engine.
- Posts Class — How tags are associated with content records.
- User Guide: Categories — Managing your site's taxonomy in the dashboard.