The GD > Single Taxonomies block ([gd_single_taxonomies]) shows a listing’s categories and tags on the details page. Its options cover most changes without code:
- Taxonomy: categories and tags (default), categories only (
cats) or tags only (tags). - Limit: the most terms to show.
- Prefix: the taxonomy name such as “Place Category:” (default), icons, or none (
0).
So this shows the categories only, with no label in front:
[gd_single_taxonomies taxonomy="cats" prefix="0"]
Show only the main category with its parents
Every listing has a default category, the main one used for its map icon and similar things. GD > Single Taxonomies lists categories in alphabetical order, so limit="1" gives you the first one alphabetically, which may not be the default.
To show just the default category, with its parent categories before it, add this snippet. It creates a [my_gd_default_category] shortcode you can place in the details page template.
add_shortcode( 'my_gd_default_category', 'my_gd_default_category_output' );
function my_gd_default_category_output() {
global $gd_post;
if ( empty( $gd_post->default_category ) ) {
return '';
}
$taxonomy = $gd_post->post_type . 'category';
$term_id = (int) $gd_post->default_category;
$term_ids = array_reverse( get_ancestors( $term_id, $taxonomy, 'taxonomy' ) );
$term_ids[] = $term_id;
$links = array();
foreach ( $term_ids as $id ) {
$term = get_term( $id, $taxonomy );
if ( $term && ! is_wp_error( $term ) ) {
$links[] = '<a href="' . esc_url( get_term_link( $term ) ) . '">' . esc_html( $term->name ) . '</a>';
}
}
return '<div class="my-gd-default-category">' . implode( ' / ', $links ) . '</div>';
}
Add it with the Code Snippets plugin. For finer changes to the block’s own output, the geodir_details_taxonomies_output filter receives the HTML for each taxonomy before it is shown. All the block options are in GD > Single Taxonomies.