Topic Trees

Improvements?

Let us know by posting here.

Topics Overview

Topics filter content, commonly blog pages, and bind to page attributes. Find them in Dashboard: System & Settings -> Attributes -> Topics.

Namespace Aliases

use \Concrete\Core\Tree\Type\Topic as TopicTree;
use \Concrete\Core\Tree\Node\Node as TreeNode;
use \Concrete\Core\Tree\Node\Type\Topic as TopicTreeNode;

Retrieve Existing Topic

$topic = TopicTreeNode::getNodeByName('News');

Add New Topic

Get 'Blog Entries' Topic Tree:

$topicTree = TopicTree::getByName('Blog Entries');

Select 'Category' or 'Reviews':

$topicCategory = TreeNode::getByID($topicTree->getRootTreeNodeObject()->treeNodeID);

// Or for 'Reviews'
use Concrete\Core\Attribute\Key\Category;
$topicCategory = new Category();
$topicCategory->getByHandle('Reviews');

Add 'Leisure' topic:

$topic = TopicTreeNode::add('Leisure', $topicCategory);

Bind Topic to Page

Get Page object by ID:

$blogEntryPage = \Page::getByID(172);

Set up 'topics' Attribute:

use Concrete\Core\Attribute\Type as AttributeType;
$attributeType = AttributeType::getByHandle('topics');

$attributeKey = CollectionAttributeKey::getByHandle('blog_entry_topics');
$akHandle = $attributeKey->getAttributeKeyHandle();
$blogEntryPage->setAttribute($akHandle, $topic->getTreeNodeDisplayPath());