Skip to content

Instantly share code, notes, and snippets.

@surma
Created August 7, 2011 19:00
Show Gist options
  • Save surma/1130655 to your computer and use it in GitHub Desktop.
Save surma/1130655 to your computer and use it in GitHub Desktop.
Peter's Liste
<!-- SNIP -->
<ul id="sources" class="meta_categories">
<?php
function getFormattedCategory($category, $show_count) {
$link = get_category_link($category->term_id);
$result = "<a href=\"".$link."\">".$category->name."</a>";
if($show_count) {
$result .= "(".$category->count.")";
}
if($category->category_description != "") {
$result .= ". ".$category->category_description;
}
return $result;
}
$args = Array("hide_empty" => 0);
$categories=get_categories($args);
$tree = Array();
foreach($categories as $category) {
$tree[$category->category_parent][count($tree[$category->category_parent])] = $category;
}
foreach($tree[0] as $supercat) {
if($supercat->name[0] != ".") {
continue;
}
echo "<li>".getFormattedCategory($supercat, true)."<ul>";
if(is_array($tree[$supercat->cat_ID])) {
foreach($tree[$supercat->cat_ID] as $subcat) {
echo "<li>".getFormattedCategory($subcat, false)."</li>";
}
}
echo "</ul></li>";
}
?>
</ul>
<!-- SNIP -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment