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:

<?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?

 
DAkers replied on at Permalink Reply
If you are talking about grabbing a custom attribute from the current page you are on, you can grab it like this.

$c = Page::getCurrentPage();
$grab_attribute = $c->getAttribute('name_of_custom_attribute');


Then you can just put the attribute into a variable in your block.
optiform replied on at Permalink Reply
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).
planist1 replied on at Permalink Best Answer Reply
planist1
optiform replied on at Permalink Reply
Perfect!

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/>";
         }
         }
planist1 replied on at Permalink Reply
planist1
Excellent! Make sure to mark the best answer so others looking for it can find it. And welcome to C5.