WordPress.org

Ready to get started?Download WordPress

Forums

Listing out terms for a taxonomy? (2 posts)

  1. jbobich
    Member
    Posted 4 years ago #

    I'm wondering what the best way to put a simple list of terms as links for a particular taxonomy is into your theme? Similar to how wp_list_pages() would list out pages or wp_list_categories() would list out categories?

    For example, maybe you have some custom post type of “products” and you have those organized in a custom taxonomy of “catalogs.” What's the best way to list out links to all of the different “catalogs”?

    This is the only way I've figured out how to do it:

    <?php $term_obj =  get_terms($taxonomy,$args); ?>
    
    <ul>
    	<?php foreach ($term_obj as $term) : ?>
    	<li><a href="<?php echo get_term_link($term->slug,$taxonomy); ?>"><?php echo $term->name; ?></a></li>
    	<?php endforeach; ?>
    </ul>

    Seems like this would be a popular thing to do and that's why my gut feeling is that the above method is more complicated than it needs to be. Anyone know anything about this? Thanks in advance!

  2. Here is what I am using to list out the terms for a custom taxonomy that contains custom posts:

    <?php query_posts( array( 'Recordings' => 'live' ) ); ?>
    <?php if( is_tax() ) {
        global $wp_query;
        $term = $wp_query->get_queried_object();
        $title = $term->name;
    }  ?>
    
    <ul>
    <span class="tax-title"><?php echo($title); ?></span>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
    
    <?php endwhile; else: ?>
    <?php endif; ?>
    </ul>

Topic Closed

This topic has been closed to new replies.

About this Topic