Minkowski
Member
Posted 2 years ago #
Hi.
I have this snippet of code but don't know how to get the permalink for the taxonomies where I've placed a #.
<?php $args = array('taxonomy' => 'news'); ?>
<?php $tax_menu_items = get_categories( $args );
foreach ( $tax_menu_items as $tax_menu_item ):?>
<li>
<a href="#">
<?php echo $tax_menu_item->name; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
I've looked through the documentation and the category-template.php file but can't seem to figure it out.
Any help would be greatly appreciated.
An example using get_term_link
$taxonomy = 'news';
$terms = get_terms( $taxonomy, '' );
if ($terms) {
foreach($terms as $term) {
echo '<p>' . '<a href="' . esc_attr(get_term_link($term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> has ' . $term->count . ' post(s). </p> ';
}
}
Minkowski
Member
Posted 2 years ago #
Aha, thanks very much! And quick too!
My final code for this is…
<ul>
<?php $args = array('taxonomy' => 'news'); ?>
<?php $tax_menu_items = get_categories( $args );
foreach ( $tax_menu_items as $tax_menu_item ):?>
<li>
<a href="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>">
<?php echo $tax_menu_item->name; ?>
</a>
</li>
<?php endforeach; ?>
</ul>