Support » Fixing WordPress » Display current taxonomy name on taxonomy.php

  • Resolved elba00



    I just can’t figure out how to display the taxonomy name when I’m viewing results on my taxomomy.php.

    I have this at the top:

    <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
    printf( __(  '%s', 'twentyten' ), '<h1>:Posts by : ' . $term->name . '</h1>' );

    Now it is working beautifully, only I can’t see the name of the current taxonomy, only the term’s name is showing up.
    I can use this:
    <?php echo $taxonomy; ?>
    But it returns the slug of the taxonomy and not the name or the singular name.

    My taxonomy slugs are abbreviations and I obviously cannot display those. If I change the slugs to normal words in functions.php and in taxonomy.php the already stored values are lost. (not lost but stored with the previous key and I really don’t know how to update/change these in phpmyadmin).

    Has anybody any idea how to display/show/query/ the actual name of the term’s taxonomy?

    Thanks guys!

Viewing 5 replies - 1 through 5 (of 5 total)
  • echo get_query_var( 'taxonomy' );

    I was thinking the same thing.. 🙂

    Not sure if that returns the name or slug though, if it returns the slug you might need to fetch the taxonomy object and print the name from there, like so..

    $the_tax = get_taxonomy( get_query_var( 'taxonomy' ) );
    echo $the_tax->labels->name;

    Thanks both of you,

    echo get_query_var( 'taxonomy' );
    returns the slug.

    I was thinking the same Mark, but I read somewhere that label is only for displaying the taxonomy name in the admin area… and I was distracted.

    Working like a charm, like every other code snippet Mark and MichaelH has been posting:

    $the_tax = get_taxonomy( get_query_var( 'taxonomy' ) );
    echo $the_tax->labels->name;


    You’re welcome… 🙂

    Many thanks. This piece of code has helped me a lot getting my single news view right.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display current taxonomy name on taxonomy.php’ is closed to new replies.