How to display singular_name of custom taxonomy?

I'm displaying list of term from each taxonomy assigned to custom post:<?php $taxonomies = get_object_taxonomies

I'm displaying list of term from each taxonomy assigned to custom post:

<?php $taxonomies = get_object_taxonomies( $post );
foreach ( $taxonomies as $taxonomy ) {

the_terms( $post->ID, $taxonomy, '<span class="e-article__category__item"><strong>' . SINGULAR_NAME . ': </strong>  ', ", ", '</span>' );
} ?>

but here, in SINGULAR_NAME I would like to display the singular_name of custom taxonomy.

I was trying this:

<?php $taxonomies = get_object_taxonomies( $post );
foreach ( $taxonomies as $taxonomy ) {

$term_name = $taxonomy->labels->singular_name;

the_terms( $post->ID, $taxonomy, '<span class="e-article__category__item"><strong>' . $term_name . ': </strong>  ', ", ", '</span>' );
} ?>

What I want to do is show all terms, separately for each taxonomy, but before each list I want to display taxonomy name (singular_name).

How to do that correctly?

Thanks :)

I'm displaying list of term from each taxonomy assigned to custom post:

<?php $taxonomies = get_object_taxonomies( $post );
foreach ( $taxonomies as $taxonomy ) {

the_terms( $post->ID, $taxonomy, '<span class="e-article__category__item"><strong>' . SINGULAR_NAME . ': </strong>  ', ", ", '</span>' );
} ?>

but here, in SINGULAR_NAME I would like to display the singular_name of custom taxonomy.

I was trying this:

<?php $taxonomies = get_object_taxonomies( $post );
foreach ( $taxonomies as $taxonomy ) {

$term_name = $taxonomy->labels->singular_name;

the_terms( $post->ID, $taxonomy, '<span class="e-article__category__item"><strong>' . $term_name . ': </strong>  ', ", ", '</span>' );
} ?>

What I want to do is show all terms, separately for each taxonomy, but before each list I want to display taxonomy name (singular_name).

How to do that correctly?

Thanks :)

Share Improve this question edited Jun 12, 2019 at 20:20 Piotr Milecki asked Jun 12, 2019 at 19:55 Piotr MileckiPiotr Milecki 253 bronze badges 2
  • Hi Piotr, what do you mean by "singular_name of CPT"? What exactly do you want to print? Could you update your question and add the effect you want to achieve? – Krzysiek Dróżdż Commented Jun 12, 2019 at 20:18
  • Cześć, Krzysztof:) I mean singular_name of custom taxonomy, my mistake :) – Piotr Milecki Commented Jun 12, 2019 at 20:20
Add a comment  | 

2 Answers 2

Reset to default 0

As far as I'm aware, your question has been answered here.

You're getting the singular_name correctly, all you need to do is echo it.

<?php $taxonomies = get_object_taxonomies( $post );
foreach ( $taxonomies as $taxonomy ) {

$term_name = $taxonomy->labels->singular_name;

echo $term_name;

the_terms( $post->ID, $taxonomy, '<span class="e-article__category__item"><strong>' . $term_name . ': </strong>  ', ", ", '</span>' );
} ?>

I finally get this done:

<?php $taxonomies = get_object_taxonomies( $post, 'objects' );
foreach ( $taxonomies as $taxonomy ) {
$tax_name = $taxonomy->labels->singular_name;
the_terms( $post->ID, $taxonomy->name, '<span class="e-article__category__item"><strong>' . $tax_name . ': </strong>  ', ", ", '</span>' );
} ?>

thanks :)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745407654a4626387.html

相关推荐

  • How to display singular_name of custom taxonomy?

    I'm displaying list of term from each taxonomy assigned to custom post:<?php $taxonomies = get_object_taxonomies

    12小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信