我有一个自定义的分级帖子类型。我有3个级别的页面,我需要一种方法来检测我是在顶级、第二级还是第三级。我对此进行了研究,只能找到使用is\\u page()的示例,但显然这不适用于CPT。
function nldf_gallery() {
$labels = array(
\'name\' => \'NLDF\',
\'singular_name\' => \'NLDF\',
\'add_new\' => \'Add New\',
\'add_new_item\' => \'Add New NLDF\',
\'edit_item\' => \'Edit NLDF\',
\'new_item\' => \'New NLDF\',
\'all_items\' => \'All NLDF\',
\'view_item\' => \'View NLDF\',
\'search_items\' => \'Search NLDF\',
\'not_found\' => \'No NLDF found\',
\'not_found_in_trash\' => \'No NLDF found in Trash\',
\'menu_name\' => \'NLDF\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'hierarchical\' => true,
\'has_archive\' => false,
\'menu_position\' => 4,
\'menu_icon\' => \'dashicons-format-gallery\',
\'supports\' => array(\'title\',\'editor\',\'comments\',\'revisions\',\'page-attributes\')
);
register_post_type(\'nldf\', $args);
}
add_action(\'init\', \'nldf_gallery\');
OR - 为每个级别的页面使用不同模板的方法