I have a custom post type that is hierarchical. I have 3 level of pages, I need a way to detect whether I am on the top level, 2nd level or 3rd level. I’ve looked into this and can only find examples that work with is_page() but apparently that doesn’t work with CPTs.
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 – A way to use a different template for each level of pages