Fetching Related Content Using Tags

Tagging is an integral part of Site Avenger's backend.  Tagging of content is done using an item's administration tool (editing pages, posts, images, etc.). Tagging content is easy for users (and easy from a programming perspective). Selecting content based on tags is another story, which is why we are constantly developing new tools to assist developers' efforts.

returnTagged($tags, $types, $options)

This is the Granddaddy of the Site Avenger tagging system.  Most of the time, you'll be dealing with this function.

Available Options

OptionDefaultValueNotes
fetchTarget true

boolean - set to true to fetch the related Model record (NewsArticle, WebPage, etc.)

This is great for simple associated lookups.  You can specify bind parameters by passing additional options in the $options parameter, indexed by the model name. 

skip null

array - ModelName => $idToExclude or ModelName => array(ids, to, exclude)

This is a shorthand approach for excluding certain model_name/model_id pairs from the tag associations lookup.

Example: to exclude the current article from the returned content, pass an options array that looks like this:

array('skip' => array('NewsArticle' => $currentArticleId));

returnIds false

boolean - set to true to return only the Model.id's of tagged content

This is useful when you are doing advance find calls (or keeping legacy code in-tact).  When this setting is active, only an array of ids will be returned.

Note: if you pass multiple $types, the format is slightly different. Model.id's will be grouped by type.

"ModelName"  null

array - settings to use for binding model_name to tag association record

 These settings will be merged with default settings in the  Tagassociation->belongsToModel() auto-binding method.

Example: to exclude the current article from related content searches, pass an options parameter as follows:

$options = array('NewsArticle' => array('conditions' => array('NewsArticle.id <>' => $currentArticleId)));

Usage Examples

You can use the contain key in the typical CakePHP fashion.

  1. $articles= $this->Tag->returnTagged('featured', 'Post', array('Post'=>array('contain'=>'Author')));

1-207-221-3255 | Contact Site Avenger - Your Content Management Superhero

Copyright © 2023 Saco Design, Inc. | All Rights Reserved | Website Design by Saco Design | Superpowered by Site Avenger