@@ -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