admin管理员组文章数量:1202373
I'm trying to pull a custom post type name/title out for use in the breadcrumb of a single-[cpt].php template file.
In the archive-[cpt].php I can use post_type_archive_title() and it echo the name. How would I get this same title in a single view?
Thanks!
I've trawled though the codex and haven't seen a function, but might have missed it!
I'm trying to pull a custom post type name/title out for use in the breadcrumb of a single-[cpt].php template file.
In the archive-[cpt].php I can use post_type_archive_title() and it echo the name. How would I get this same title in a single view?
Thanks!
I've trawled though the codex and haven't seen a function, but might have missed it!
Share Improve this question asked Feb 1, 2012 at 15:10 Mere DevelopmentMere Development 3091 gold badge6 silver badges20 bronze badges1 Answer
Reset to default 6There doesn't appear to be one, but the following should work:
//Get post type
$post_type_obj = get_post_type_object( get_post_type() );
//Get post type's label
$title = apply_filters('post_type_archive_title', $post_type_obj->labels->name );
$archive_title = apply_filters('post_type_archive_title', $post_type_obj->labels->all_items);
This can, for instance, be put in one generic header
template that is applied to all single-cpt
files. With is_single()
it can be put in an even more generic header
template.
For a complete list of labels, see http://codex.wordpress.org/Function_Reference/register_post_type#Arguments
本文标签: custom post typesNeed posttypearchivetitle function but in 39single39
版权声明:本文标题:custom post types - Need post_type_archive_title function but in 'single' 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738648167a2104711.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论