Custom attributes as tag block
Permalink
I'm new to C5 and a bit of a novice to php. I've been searching and haven't been able to find anything close to what I'm looking for.
I'd like to create a secondary tag cloud from a custom attribute. I've seen this code:
Is it possible to get the custom attribute collection and have it behave like a tag block?
I'd like to create a secondary tag cloud from a custom attribute. I've seen this code:
<?php $tagsBT = BlockType::getByHandle('tags') $tagsBT->controller->attributeHandle = "tags"; $targetPage = Page::getByPath('/projects/project-search-results'); $tagsBT->controller->targetCID = $targetPage->getCollectionID(); $tagsBT->controller->displayMode = 'cloud'; $tagsBT->controller->cloudCount = '10'; $tagsBT->render('templates/sidebar/view'); ?>
Is it possible to get the custom attribute collection and have it behave like a tag block?
I want to grab all of the values (not just the current page) from a custom attribute and display them like a tag block. When the users click on the echoed value, it takes them to the search result page (like the tag block).
This post might prove useful...http://www.concrete5.org/community/forums/customizing_c5/get-attrib...
Perfect!
I have this:
Now I just need to figure out how to link the values to the search page. I assume it would be implementing getLinkToCollection() somewhere?
EDIT:
Never mind, I just used the URL to pass the value =D
I have this:
$db = Loader::db(); $r = $db->query("SELECT distinct ak_vendor FROM CollectionSearchIndexAttributes"); $myValues = array(); while ($row = $r->fetchRow()) { //search for multiple values $valueArray = explode("\n",$row['ak_vendor']); foreach ($valueArray as $value) { $myValues[] = $value; echo $value . "<br/>"; } }
Now I just need to figure out how to link the values to the search page. I assume it would be implementing getLinkToCollection() somewhere?
EDIT:
Never mind, I just used the URL to pass the value =D
$db = Loader::db(); $r = $db->query("SELECT distinct ak_vendor FROM CollectionSearchIndexAttributes"); $myValues = array(); while ($row = $r->fetchRow()) { //search for multiple values $valueArray = explode("\n",$row['ak_vendor']); foreach ($valueArray as $value) { $myValues[] = $value; echo "<a href='/index.php/search/?search_paths%5B%5D=&query=" . $value . "&submit=Search'>" . $value . "</a><br/>"; } }
Excellent! Make sure to mark the best answer so others looking for it can find it. And welcome to C5.
Then you can just put the attribute into a variable in your block.