Want more features on Pastebin? Sign Up, it's FREE!
Guest

Display/show/list custom terms in heirarchy order - not alph

By: pjeaje on Sep 17th, 2013  |  syntax: HTML  |  size: 1.46 KB  |  views: 85  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <p>111</p>
  2. <?php
  3. $taxonomy = 'program';
  4. // get the term IDs assigned to post.
  5. $post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
  6. // separator between links
  7. $separator = ', ';
  8. if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) {
  9.         $term_ids = implode( ',' , $post_terms );
  10.         $terms = wp_list_categories( 'title_li=&style=none&echo=0&taxonomy=' . $taxonomy . '&include=' . $term_ids );
  11.         $terms = rtrim( trim( str_replace( '<br />',  $separator, $terms ) ), $separator );
  12.         // display post categories
  13.         echo  $terms;
  14. }
  15. ?>
  16.  
  17. <p>222</p>
  18. <?php
  19. //list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)
  20. $taxonomy     = 'program';
  21. $orderby      = 'name';
  22. $show_count   = 0;      // 1 for yes, 0 for no
  23. $pad_counts   = 0;      // 1 for yes, 0 for no
  24. $hierarchical = 1;      // 1 for yes, 0 for no
  25. $title        = '';
  26. $args = array(
  27.  'taxonomy'     => $taxonomy,
  28.   'orderby'      => $orderby,
  29.   'show_count'   => $show_count,
  30.   'pad_counts'   => $pad_counts,
  31.   'hierarchical' => $hierarchical,
  32.   'title_li'     => $title
  33. );
  34. ?>
  35. <ul>
  36. <?php wp_list_categories( $args ); ?>
  37. </ul>
  38.  
  39. <p>333</p>
  40. <?php echo get_the_term_list( $post->ID, 'program', '', ', ', '' ); ?>
  41.  
  42.  
  43. <p>444</p>
  44. <?php the_terms( $post->ID, 'program', 'Program: ', ' / ' ); ?>
  45.  
  46. <p>555</p>
  47. <?php echo '<p>';
  48. echo get_the_term_list( $post->ID, 'program', '   ', ' &middot; ', ' ' );
  49. echo '</p>'; ?>
clone this paste RAW Paste Data