Listing all terms in taxonomy in alphabetic order with reference of alphabets
- by admin
- 0
call shortcode [show_taxonomies]
Add the following code in your function.php
add_shortcode( ‘show_taxonomies’, ‘listing_taxonomies’ );
function listing_taxonomies(){
$terms = get_terms( array(
‘taxonomy’ => ‘writer’, // taxonomy name
‘orderby’ => ‘name’,
‘hide_empty’ => false,
) );
$tax_list = array();
foreach ( $terms as $term ) {
$name = strtolower($term->name);
$slug = $term->slug;
$first_letter = substr($name, 0, 1); // getting first
if(!array_key_exists($first_letter, $tax_list))
$tax_list[$first_letter] = array($slug => $name);
else
$tax_list[$first_letter][$slug] = $name;
}
$output = ‘<div class=”brandlist-container”>’;
foreach( $tax_list as $key_letter => $terms_in_letter ){
$output .= ‘<span class=”list_first_letter” id=”‘. strtolower( $key_letter ) .'”>’. $key_letter .'</span>
<ul class=”author_list”>’;
// second level the $name / $slug pairs
foreach( $terms_in_letter as $key => $value ){
$url= home_url().”/writer/”.$key;
$output .= ‘<li class=”author_name”><a href=”‘.$url.'”>’.$value.'</a></li>’;
}
$output .= ‘</ul>’;
}
$output .= ‘</div>’;
return $output;
}
call shortcode [show_taxonomies] Add the following code in your function.php add_shortcode( ‘show_taxonomies’, ‘listing_taxonomies’ ); function listing_taxonomies(){ $terms = get_terms( array( ‘taxonomy’ => ‘writer’, // taxonomy name ‘orderby’ => ‘name’, ‘hide_empty’ => false, ) ); $tax_list = array(); foreach ( $terms as $term ) { $name = strtolower($term->name); $slug = $term->slug; $first_letter = substr($name, 0, 1);…
call shortcode [show_taxonomies] Add the following code in your function.php add_shortcode( ‘show_taxonomies’, ‘listing_taxonomies’ ); function listing_taxonomies(){ $terms = get_terms( array( ‘taxonomy’ => ‘writer’, // taxonomy name ‘orderby’ => ‘name’, ‘hide_empty’ => false, ) ); $tax_list = array(); foreach ( $terms as $term ) { $name = strtolower($term->name); $slug = $term->slug; $first_letter = substr($name, 0, 1);…