I'm trying to make a unordered list of my custom taxonomies just at wp_list_categories(); does for standard categories.
If my custom taxonomy is "industry" and I have three industries inputed (A, B & C) --- I want it to list the industries with links to each "category page" for each "industry" like so:
Industries:
I've searched around and tried several clips of code and functions, but have yet to get anything to work. Please help! Thanks in advance.
<?php
//list terms in a given taxonomy
$taxonomy = 'industry';
$tax_terms = get_terms($taxonomy);
?>
<ul>
<?php
foreach ($tax_terms as $tax_term) {
echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></li>';
}
?>
</ul>
@MichaelH
Thank you for the code snippet. I tried using it and did not get any results displayed. I tried the code snippet inside and outside of a loop. I'm trying to display this on a custom home page. I have several different custom loops running on the page.
What do you think the issue may be?
Before this line
//list terms in a given taxonomy
put
echo '<h2>listing taxonomy</h2>';
That way you know if the code is executing.
If necessary, please provide a link to your site and put all the code from that template in a pastebin like wordpress.pastebin.com and report the link back here and maybe someone can spot the problem.
@MichaelH
The code seems to be executing. It echoes the h2 tag. The site is currently local only, but here's a link to the code itself. I really appreciate the help.
http://wordpress.pastebin.com/AVNcUqN6
The lines of code that are not working are in lines 66-78.
I just threw that code in the index.php (using TwentyTen theme) of a test install and it worked fine.
Don't know what I'm doing wrong here. I tried the same thing with no luck. The site is WPMS and the the custom taxonomy is created with the More Taxonomies plugin.
I tried it on a different normal install with a manually created taxonomy as well. :-/
Don't know about the WPMS, but if that plugin creates normal taxonomies don't know why it wouldn't work unless the taxonmies are empty--if so try
$taxonomy = 'industry';
$term_args=array(
'hide_empty' => false,
'orderby' => 'name',
'order' => 'ASC'
);
$tax_terms = get_terms($taxonomy,$term_args);
That works like a charm! Thank you so much for the help. I get it now. There's no posts in them, so they don't display. Doh! >.<
Well, I need to them to display even if they are empty, so I appreciate your troubleshooting with me.