WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display current taxonomy name on taxonomy.php (6 posts)

  1. elba00
    Member
    Posted 3 years ago #

    Hi,

    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!

  2. MichaelH
    Member
    Posted 3 years ago #

    echo get_query_var( 'taxonomy' );
  3. Mark / t31os
    Moderator
    Posted 3 years ago #

    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;
  4. elba00
    Member
    Posted 3 years ago #

    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;

    Thanks.

  5. Mark / t31os
    Moderator
    Posted 3 years ago #

    You're welcome... :)

  6. netscout
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic