我使用以下代码创建了一个名为30天训练营的自定义帖子类型:
add_action( \'init\', \'rt_custom_post\' );
function rt_custom_post() {
register_post_type( \'30-day-boot-camp\',
array(
\'labels\' => array(
\'name\' => __( \'Boot Camps\' ),
\'singular_name\' => __( \'Boot Camp\' ),
\'add_new\' => _x(\'Add New\', \'Boot Camp\'),
\'add_new_item\' => __("Add New Boot Camp"),
\'edit_item\' => __("Edit Boot Camp"),
\'new_item\' => __("New Boot Camp"),
\'view_item\' => __("View Boot Camp"),
\'search_items\' => __("Search in Boot Camps"),
\'not_found\' => __(\'No Boot Camp\'),
\'not_found_in_trash\' => __(\'No Boot Camp found in Trash\')
),
\'public\' => true,
\'has_archive\' => true,
\'menu_icon\' => \'dashicons-calendar-alt\',
\'supports\' => array(\'title\',\'editor\',\'thumbnail\',\'author\'),
)
);
}
当我在归档页面(archive-30-day-boot-camp.php)上时,我可以通过以下代码提取训练营的名称:
<?php if ( is_post_type_archive( \'30-day-boot-camp\' ) ) : ?>
<h1 class="h-landmark entry-title"><span>
<?php post_type_archive_title(); ?></span></h1>
<?php endif?>
它返回“新兵训练营”
然而,当我在(single-30-day-boot-camp.php)上访问一个条目时,我无法理解如何返回自定义的帖子类型名称。我想让它回归“训练营”,而不仅仅是帖子标题本身。(例如,可以是“第1天”。)
我试过:
<?php post_type_archive_title(\'\'); ?>
但什么都没出现
我也试过了
<?php post_type_archive_title(\'30-day-boot-camp\'); ?>