Вывел произвольный тип записи, после этого написал singe-page для этого типа записи, столкнулся с тем, что в хлебных крошках не отображается цепочка, а только ссылка на главную. Думаю что нужно выбрать родительскую страницу для этой записи, но в админке нет селекта с атрибутами страницы. Подскажите, как добавить этот параметр в админку, или как вывести хлебные крошки для произвольного типа записей?
// Регистрируем тип произвольных записей
add_action('init', 'register_post_types');
function register_post_types()
{
register_post_type('post_type_1', array(
'label' => null,
'labels' => array(
'name' => 'Спецтехника', // основное название для типа записи
'singular_name' => '____', // название для одной записи этого типа
'add_new' => 'Добавить позицию', // для добавления новой записи
'add_new_item' => 'Добавление позиции', // заголовка у вновь создаваемой записи в админ-панели.
'edit_item' => 'Редактирование позиции', // для редактирования типа записи
'new_item' => 'Новая позиция', // текст новой записи
'view_item' => 'Смотреть позицию', // для просмотра записи этого типа.
'search_items' => 'Искать позицию', // для поиска по этим типам записи
'not_found' => 'Не найдено', // если в результате поиска ничего не было найдено
'not_found_in_trash' => 'Не найдено в корзине', // если не было найдено в корзине
'parent_item_colon' => 'post_type_1', // для родителей (у древовидных типов)
'menu_name' => 'Спецтехника', // название меню
),
'description' => '',
'public' => true,
// 'publicly_queryable' => null, // зависит от public
// 'exclude_from_search' => null, // зависит от public
// 'show_ui' => null, // зависит от public
// 'show_in_nav_menus' => null, // зависит от public
'show_in_menu' => null, // показывать ли в меню адмнки
// 'show_in_admin_bar' => null, // зависит от show_in_menu
'show_in_rest' => null, // добавить в REST API. C WP 4.7
'rest_base' => null, // $post_type. C WP 4.7
'menu_position' => null,
'menu_icon' => 'dashicons-dashboard',
//'capability_type' => 'post',
//'capabilities' => 'post', // массив дополнительных прав для этого типа записи
'map_meta_cap' => null, // Ставим true чтобы включить дефолтный обработчик специальных прав
'hierarchical' => false,
'supports' => ['title', 'thumbnail', 'custom-fields', 'editor', 'page-attributes'], // 'title','editor','author','thumbnail','excerpt','trackbacks','custom-fields','comments','revisions','page-attributes','post-formats'
'taxonomies' => array('category', 'post_tag'),
'has_archive' => false,
'rewrite' => true,
'query_var' => true,
));
add_theme_support('post-thumbnails');
}
// Breadcrumb
/**
* Retrieve category parents.
*
* @param int $id Category ID.
* @param array $visited Optional. Already linked to categories to prevent duplicates.
* @return string|WP_Error A list of category parents on success, WP_Error on failure.
*/
function custom_get_category_parents( $id, $visited = array() ) {
$chain = '';
$parent = get_term( $id, 'category' );
if ( is_wp_error( $parent ) )
return $parent;
$name = $parent->name;
if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
$visited[] = $parent->parent;
$chain .= custom_get_category_parents( $parent->parent, $visited );
}
$chain .= '<li class="breadcrumb-item"><a href="' . esc_url( get_category_link( $parent->term_id ) ) . '">' . $name. '</a>' . '</li>';
return $chain;
}
function bootstrap_breadcrumb() {
global $post;
$html = '<ol class="breadcrumb">';
if ( (is_front_page()) || (is_home()) ) {
$html .= '<li class="breadcrumb-item active">Главная</li>';
}
else {
$html .= '<li class="breadcrumb-item"><a href="'.esc_url(home_url('/')).'">Главная</a></li>';
if ( is_attachment() ) {
$parent = get_post($post->post_parent);
$categories = get_the_category($parent->ID);
if ( $categories[0] ) {
$html .= custom_get_category_parents($categories[0]);
}
$html .= '<li class="breadcrumb-item"><a href="' . esc_url( get_permalink( $parent ) ) . '">' . $parent->post_title . '</a></li>';
$html .= '<li class="breadcrumb-item active">' . get_the_title() . '</li>';
}
elseif ( is_category() ) {
$category = get_category( get_query_var( 'cat' ) );
if ( $category->parent != 0 ) {
$html .= custom_get_category_parents( $category->parent );
}
$html .= '<li class="breadcrumb-item active">' . single_cat_title( '', false ) . '</li>';
}
elseif ( is_page() && !is_front_page() ) {
$parent_id = $post->post_parent;
$parent_pages = array();
while ( $parent_id ) {
$page = get_page($parent_id);
$parent_pages[] = $page;
$parent_id = $page->post_parent;
}
$parent_pages = array_reverse( $parent_pages );
if ( !empty( $parent_pages ) ) {
foreach ( $parent_pages as $parent ) {
$html .= '<li class="breadcrumb-item"><a href="' . esc_url( get_permalink( $parent->ID ) ) . '">' . get_the_title( $parent->ID ) . '</a></li>';
}
}
$html .= '<li class="breadcrumb-item active">' . get_the_title() . '</li>';
}
elseif ( is_singular( 'post' ) ) {
$categories = get_the_category();
if ( $categories[0] ) {
$html .= custom_get_category_parents($categories[0]);
}
$html .= '<li class="breadcrumb-item active">' . get_the_title() . '</li>';
}
elseif ( is_tag() ) {
$html .= '<li class="breadcrumb-item active">' . single_tag_title( '', false ) . '</li>';
}
elseif ( is_day() ) {
$html .= '<li class="breadcrumb-item"><a href="' . esc_url( get_year_link( get_the_time( 'Y' ) ) ) . '">' . get_the_time( 'Y' ) . '</a></li>';
$html .= '<li class="breadcrumb-item"><a href="' . esc_url( get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) ) . '">' . get_the_time( 'm' ) . '</a></li>';
$html .= '<li class="breadcrumb-item active">' . get_the_time('d') . '</li>';
}
elseif ( is_month() ) {
$html .= '<li class="breadcrumb-item"><a href="' . esc_url( get_year_link( get_the_time( 'Y' ) ) ) . '">' . get_the_time( 'Y' ) . '</a></li>';
$html .= '<li class="breadcrumb-item active">' . get_the_time( 'F' ) . '</li>';
}
elseif ( is_year() ) {
$html .= '<li class="breadcrumb-item active">' . get_the_time( 'Y' ) . '</li>';
}
elseif ( is_author() ) {
$html .= '<li class="breadcrumb-item active">' . get_the_author() . '</li>';
}
elseif ( is_search() ) {
}
elseif ( is_404() ) {
}
}
$html .= '</ol>';
echo $html;
}