Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Jorinde

    (@jorinde)

    Alright! Yes, my problem is solved. Thanks for your help.

    Thread Starter Jorinde

    (@jorinde)

    Michael, that worked like charm!
    I promise to dig deeper into this whole PHP thing, thank you so much for providing me with the necessary pointers.

    This is my full code now. I use this bit about 12 times in the template, for the various taxonomies. Is there a downside to that?

    <?php $taxonomy = 'habitat';
    $tax_args=array('orderby' => 't.term_id');
    $terms = wp_get_post_terms( $post->ID , $taxonomy, $tax_args);
    if ($terms) {
    echo '<li> <strong>Habitat:</strong> ';
    foreach ($terms as $term) {
    echo '<a href="' . esc_attr(get_term_link($term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> ';
    }
    echo '</li>';
    } ?>

    Thread Starter Jorinde

    (@jorinde)

    Fantastic! That is exactly what I was looking for.

    Now I only have two issues left:
    How can I exclude/hide empty taxonomies? In other words, with the original (non-sortable) solution that employed the_terms, I could define before and after bits—<li> <strong>Habitat:</strong> and </li>—that were displayed only when there was a value. How can I prevent such an empty label now?

    The other thing is: the hierarchy of the terms is not reflected by the URL. It is /habitat/france, instead of/habitat/europe/france. Can the URLs show the hierarchy? If there is no easy/known fix to the latter, I will dismiss the plan.

    Thank you for your patience.

    Thread Starter Jorinde

    (@jorinde)

    Michael, thank you for your quick response.
    I tried your proposal: yes, it works: it returns the slugs, ordered by ID. What I need are the names, with a link to the respective archive (sorry for not being clear about that in my first post). I have figured out that I can get the name when I change slug to name. But what about the links?
    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)