admin管理员组文章数量:1315792
In my content-search.php template file I did something like this:
<tr id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<td><?php the_post_thumbnail( 'thumbnail' ); ?></td>
<td style="padding: 15px;">
<?php
echo '<h6>' . ucfirst( get_post_type( get_the_ID() ) ) . '</h6>';
the_title( sprintf( '<h5><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h5>' );
echo '<p>' . get_the_excerpt() . '</p>';
?>
</td>
</tr>
It returns posts image, post type name in English, title and excerpt on search results page. Posts, pages or another custom post types by searched term. I need to display post type name translated into another language.
In my content-search.php template file I did something like this:
<tr id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<td><?php the_post_thumbnail( 'thumbnail' ); ?></td>
<td style="padding: 15px;">
<?php
echo '<h6>' . ucfirst( get_post_type( get_the_ID() ) ) . '</h6>';
the_title( sprintf( '<h5><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h5>' );
echo '<p>' . get_the_excerpt() . '</p>';
?>
</td>
</tr>
It returns posts image, post type name in English, title and excerpt on search results page. Posts, pages or another custom post types by searched term. I need to display post type name translated into another language.
Share Improve this question asked Nov 16, 2020 at 12:55 JurajJuraj 1542 silver badges11 bronze badges1 Answer
Reset to default 1Based on a previous Q&A, How to get current get_post_types name?, you could use get_post_type_object()
to get the whole post type object, which will have the translated name in it.
$post_type_object = get_post_type_object(get_post_type());
if ( $post_type_object ) {
echo esc_html( $post_type_object->labels->singular_name );
}
本文标签: translationHow to display getposttype() translated
版权声明:本文标题:translation - How to display get_post_type() translated? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741991087a2409118.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论