WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] List categories for custom post type (7 posts)

  1. DennisvanHouts
    Member
    Posted 3 years ago #

    I registered a custom post type (called product) with a custom taxonomy (calles type, it's hierarchical). Now I want to display all those product types in a list, just as you would display the post categories.

    I'm trying something like this:
    wp_list_categories(array('taxonomy' => 'type'));

    This shows exactly what I want, a list of all those types with also the subtypes. Only problem is that the links don't show up right. They point to the post category page (http://www.test.com/category/).

    Anyone any ideas to make a list for the custom taxonomy?

  2. MichaelH
    Member
    Posted 3 years ago #

    This works in a widget at least testing with the coming 3.0

    <?php
    //list terms in a given taxonomy (useful as a widget for twentyten)
    $taxonomy = 'genre';
    $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. DennisvanHouts
    Member
    Posted 3 years ago #

    It does work.

    Only thing: now all the taxonomies are nicely listed, but because the taxonomy is hierarchical I want to show the subtaxonomies onder their parent.

    When listing categories for posts, the child is listed under the parent automaticly, can this be also be done for taxonomies?

  4. MichaelH
    Member
    Posted 3 years ago #

    Didn't realize you could do this, but you will like it! Beware the 'taxonomy' argument with wp_list_categories is only available in the coming 3.0 (or the 3.0 beta if you are using that).

    <?php
    //list terms in a given taxonomy using wp_list_categories  (also useful as a widget)
    $orderby = 'name';
    $show_count = 0; // 1 for yes, 0 for no
    $pad_counts = 0; // 1 for yes, 0 for no
    $hierarchical = 1; // 1 for yes, 0 for no
    $taxonomy = 'genre';
    $title = '';
    
    $args = array(
      'orderby' => $orderby,
      'show_count' => $show_count,
      'pad_counts' => $pad_counts,
      'hierarchical' => $hierarchical,
      'taxonomy' => $taxonomy,
      'title_li' => $title
    );
    ?>
    <ul>
    <?php
    wp_list_categories($args);
    ?>
    </ul>
  5. DennisvanHouts
    Member
    Posted 3 years ago #

    Yes, I'm using the 3.0 beta. Using your code it shows the taxonomies and subtaxonomies the way I want it, but the links it generates aren't correct.

    All the links point to the category page.

    Like this:
    http://test.com/blog/category/

    Links should be like this, e.g.:
    http://test.com/blog/type/chair/

  6. DennisvanHouts
    Member
    Posted 3 years ago #

    No, sorry, I take it back. I was using the alpha release in which it didn't work. It does work in the beta release. Thanks, this helps alot!

  7. vehler
    Member
    Posted 3 years ago #

    Hi, im using the beta release and im not able to display custom taxonomies. I have used the code above and nothing. Also the custom taxonomies are not showing up in the new menu editor, will that be available on the oficial release?

Topic Closed

This topic has been closed to new replies.

About this Topic