Skip to content

Commit 006954d

Browse files
committed
feedback
1 parent 76ec28f commit 006954d

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

packages/block-library/src/breadcrumbs/edit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ export default function BreadcrumbEdit( {
118118

119119
// Try to determine breadcrumb type for more accurate previews.
120120
let _showTerms;
121-
// For non-hierarchical post types with a parent (e.g., attachments) use ancestor-based breadcrumbs.
121+
// Some non-hierarchical post types (e.g., attachments) can have parents.
122+
// Use hierarchical breadcrumbs if a parent exists, otherwise use taxonomy breadcrumbs.
122123
if ( ! isPostTypeHierarchical && ! post?.parent ) {
123124
_showTerms = true;
124125
} else if ( ! postTypeHasTaxonomies ) {

packages/block-library/src/breadcrumbs/index.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,35 +77,34 @@ function render_block_core_breadcrumbs( $attributes, $content, $block ) {
7777
}
7878

7979
// For non-hierarchical post types with parents (e.g., attachments), build trail for the parent.
80-
$trail_post_id = $post_id;
81-
$trail_post_type = $post_type;
82-
$trail_post_parent = $post->post_parent;
83-
$parent_post = null;
84-
if ( ! is_post_type_hierarchical( $post_type ) && $post->post_parent ) {
85-
$parent_post = get_post( $post->post_parent );
80+
$post_parent = $post->post_parent;
81+
$parent_post = null;
82+
if ( ! is_post_type_hierarchical( $post_type ) && $post_parent ) {
83+
$parent_post = get_post( $post_parent );
8684
if ( $parent_post ) {
87-
// Use parent post for the breadcrumb trail.
88-
$trail_post_id = $parent_post->ID;
89-
$trail_post_type = $parent_post->post_type;
90-
$trail_post_parent = $parent_post->post_parent;
85+
$post_id = $parent_post->ID;
86+
$post_type = $parent_post->post_type;
87+
$post_parent = $parent_post->post_parent;
9188
}
9289
}
9390

9491
// Determine breadcrumb type.
92+
// Some non-hierarchical post types (e.g., attachments) can have parents.
93+
// Use hierarchical breadcrumbs if a parent exists, otherwise use taxonomy breadcrumbs.
9594
$show_terms = false;
96-
if ( ! is_post_type_hierarchical( $trail_post_type ) && ! $trail_post_parent ) {
95+
if ( ! is_post_type_hierarchical( $post_type ) && ! $post_parent ) {
9796
$show_terms = true;
98-
} elseif ( empty( get_object_taxonomies( $trail_post_type, 'objects' ) ) ) {
97+
} elseif ( empty( get_object_taxonomies( $post_type, 'objects' ) ) ) {
9998
$show_terms = false;
10099
} else {
101100
$show_terms = $attributes['prefersTaxonomy'];
102101
}
103102

104103
// Build breadcrumb trail.
105104
if ( ! $show_terms ) {
106-
$breadcrumb_items = array_merge( $breadcrumb_items, block_core_breadcrumbs_get_hierarchical_post_type_breadcrumbs( $trail_post_id ) );
105+
$breadcrumb_items = array_merge( $breadcrumb_items, block_core_breadcrumbs_get_hierarchical_post_type_breadcrumbs( $post_id ) );
107106
} else {
108-
$breadcrumb_items = array_merge( $breadcrumb_items, block_core_breadcrumbs_get_terms_breadcrumbs( $trail_post_id, $trail_post_type ) );
107+
$breadcrumb_items = array_merge( $breadcrumb_items, block_core_breadcrumbs_get_terms_breadcrumbs( $post_id, $post_type ) );
109108
}
110109

111110
// Add parent post title if applicable.

0 commit comments

Comments
 (0)