Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor fireproofsocks

    (@fireproofsocks)

    There are built-in WordPress functions to help display taxonomy data, but they are regrettably inconsistent and confusingly documented.

    Here are a few links :

    * http://codex.wordpress.org/Function_Reference/wp_get_post_categories
    * http://codex.wordpress.org/Function_Reference/get_categories
    * http://codex.wordpress.org/Function_Reference/get_category

    <div style="display: block;" id="mnu_type">
    <ul>
                    <?php
                      $args = array(
    		    'show_option_all'    => '',
                        'orderby'            => 'ID',
                        'order'              => 'ASC',
                        'style'              => 'list',
                        'show_count'         => 1,
                        'hide_empty'         => 0,
                        'use_desc_for_title' => 1,
                        'child_of'           => 0,
                        'hierarchical'       => true,
                        'title_li'           => '',
                        'show_option_none'   => __('No Directory Orgs'),
                        'number'             => NULL,
                        'echo'               => 1,
                        'depth'              => 0,
                        'current_category'   => 0,
                        'pad_counts'         => 1,
                        'taxonomy'           => 'your_taxonomy_name',
                        'walker'             => 'Walker_Category' );
                      wp_list_categories($args); ?>
                  </ul>
    </div>
    J

    (@paradox_designs)

    This is not very helpful. I want to show just the current “category” or taxonomy.

    You have “print_custom_field(‘field_name’);” to display the field data, what do I write to display a taxonomy data?

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Sorry, that’s not really a CCTM question, it’s a WordPress one, and yes, as I stated previously the WP functions are often confusing, poorly thought-out, inconsistent, and difficult to use. Any single post (of any type) can have many taxonomies, so it’s never as simple as just printing a single value (as is done with the print_custom_field() example): you are always retrieving a list of results, so you have to loop over them somehow.

    The example on http://codex.wordpress.org/Function_Reference/wp_get_post_categories is relevant to you. Here it is a bit more verbosely modified:

    $post_categories = wp_get_post_categories( $post_id );
    foreach($post_categories as $c){
        print '<li><a href="'.get_term_link($c->slug, $c->name).'">'.$c->name.'</a></li>';
    }
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Display Taxonomy in content single post’ is closed to new replies.