WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Listing Custom Taxonomy Terms (9 posts)

  1. David Calhoun
    Member
    Posted 3 years ago #

    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:

    • A
    • B
    • C

    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.

  2. MichaelH
    Member
    Posted 3 years ago #

    <?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>
  3. David Calhoun
    Member
    Posted 3 years ago #

    @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?

  4. MichaelH
    Member
    Posted 3 years ago #

    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.

  5. David Calhoun
    Member
    Posted 3 years ago #

    @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.

  6. MichaelH
    Member
    Posted 3 years ago #

    I just threw that code in the index.php (using TwentyTen theme) of a test install and it worked fine.

  7. David Calhoun
    Member
    Posted 3 years ago #

    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. :-/

  8. MichaelH
    Member
    Posted 3 years ago #

    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);
  9. David Calhoun
    Member
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic