Advertisement
vtxyzzy

Post Category Links Sorted by Name

Mar 23rd, 2012
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. <?php
  2.  
  3. // Print an alphabetical list of category links for a post
  4. $id = $post->ID;
  5. $category = 'directorycategory';
  6.  
  7. $terms = get_the_term_list( $id, $category, '', '||', '' );
  8.  
  9. $term_array = explode('||', $terms);
  10. $keyed_array = array();
  11. foreach ($term_array as $term) {
  12.    // Get the term name
  13.    if ( preg_match('/>([^<]*)<\/a>/', $term, $matches) ) {
  14.       $keyed_array[strtoupper($matches[1])] = $term;
  15.    }
  16. }
  17. ksort($keyed_array);
  18. echo '<div class="specialties">';
  19. $sep = ' ';
  20. foreach ( array_keys($keyed_array) as $key) {
  21.    echo "$sep$keyed_array[$key]";
  22.    $sep = ', ';
  23. }
  24. echo '</div>';
  25.  
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement