Nachfolgend beschrieben ist ein Shortcode, der (custom) Taxonomy Terms (also Schlagworte aus benutzerdefinierten Taxonomien) auflistet:
<?php
function sw_shortcode_list_taxonomy_terms($attributes)
{
$attributes = shortcode_atts(array(
'taxonomy' => 'post_tag',
'orderby' => 'name',
), $attributes);
$args = array(
'taxonomy' => $attributes['taxonomy'],
'orderby' => $attributes['orderby'],
);
$terms = get_categories($args);
$output = '';
// Exit if there are no terms
if (!$terms) {
return $output;
}
// Start list
$output .= '<ul>';
// Add terms
foreach ($terms as $term) {
$output .= '<li><a href="'.get_term_link($term).'">'.esc_html($term->cat_name).'</a></li>';
}
// End list
$output .= '</ul>';
return $output;
}
add_shortcode('taxonomy_terms', 'sw_shortcode_list_taxonomy_terms');
Standardmäßig listet der Shortcode `[taxonomy_terms]` die Schlagworte des Posts auf. Um die Schlagworte einer anderen Taxonomy auszugeben, einfach folgenden Code nutzen:
[taxonomy_terms taxonomy=“my_taxonomy”]