Skip to content

Instantly share code, notes, and snippets.

@avoronkin
Created May 26, 2011 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avoronkin/992827 to your computer and use it in GitHub Desktop.
Save avoronkin/992827 to your computer and use it in GitHub Desktop.
MODX Evolution simple tag list
<?php
//$landingID = 35;
$tb1 = $modx->getFullTableName("site_tmplvar_contentvalues");
$query = "SELECT value";
$query .= " FROM ".$tb1;
$query .= " WHERE tmplvarid=".$tvID;
$query .= " GROUP BY value";
$query .= " ORDER BY id DESC";
$query .= " LIMIT 50;";
//echo $query;
$result = $modx->db->query($query);
// here we loop through the results and put them into a simple array:
$tag_mess = array();
while ($row = $modx->db->getRow( $result )) {
$tags = explode(',',$row['value']);
$tag_mess = array_merge($tag_mess, $tags);
}
$tags = array_count_values($tag_mess);
arsort($tags);
$tags = array_slice($tags, 0, 30);
ksort($tags);
// loop through our tag array
foreach ($tags as $key => $value) {
$class = '';
if($_GET['tags'] == $key){ $class = 'active';}
$output .= '<li class="'.$class.'"><a href="/[~'.$landingID.'~]?tags='.urlencode($key).'" >'.$key.'</a></li> ';
}
return $output;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment