Skip to content

Instantly share code, notes, and snippets.

@samuelsimoes
Created May 4, 2012 17:30
Show Gist options
  • Save samuelsimoes/2596395 to your computer and use it in GitHub Desktop.
Save samuelsimoes/2596395 to your computer and use it in GitHub Desktop.
Função pra gerar uma lista a partir de uma taxonomia
<?php
function gerar_menu_taxonomia($taxonomia_nome){
$args = array('taxonomy' => $taxonomia_nome, 'parent' => '0');
$taxonomias = get_categories($args);
echo "<ul>";
foreach ($taxonomias as $taxonomia) {
echo "<li>";
echo "<a href='" . get_term_link($taxonomia, $taxonomia_nome) . "'>";
echo $taxonomia->name;
echo "</a>";
$taxonomias_filhas = get_categories(array('taxonomy' => $taxonomia_nome, 'parent' => $taxonomia->cat_ID));
if($taxonomias_filhas) {
echo "<ul>";
foreach ($taxonomias_filhas as $taxonomia_filha) {
echo "<li>";
echo "<a href='" . get_term_link($taxonomia_filha, $taxonomia_nome) . "'>";
echo $taxonomia_filha->name;
echo "</a></li>";
}
echo "</ul>";
}
echo "</li>";
}
echo "</ul>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment