Astra_Breadcrumb_Trail::add_post_parents( int $post_id )
Adds a specific post’s parents to the items array.
Description
Parameters
- $post_id
-
(int) (Required)
Return
(void)
Source
File: inc/addons/breadcrumbs/class-astra-breadcrumb-trail.php
protected function add_post_parents( $post_id ) {
$parents = array();
while ( $post_id ) {
// Get the post by ID.
$post = get_post( $post_id );
// If we hit a page that's set as the front page, bail.
if ( 'page' == $post->post_type && 'page' == get_option( 'show_on_front' ) && $post_id == get_option( 'page_on_front' ) ) {
break;
}
// Add the formatted post link to the array of parents.
$parents[] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( $post_id ) ), get_the_title( $post_id ) );
// If there's no longer a post parent, break out of the loop.
if ( 0 >= $post->post_parent ) {
break;
}
// Change the post ID to the parent post to continue looping.
$post_id = $post->post_parent;
}
// Get the post hierarchy based off the final parent post.
$this->add_post_hierarchy( $post_id );
// Display terms for specific post type taxonomy if requested.
if ( ! empty( $this->post_taxonomy[ $post->post_type ] ) ) {
$this->add_post_terms( $post_id, $this->post_taxonomy[ $post->post_type ] );
}
// Merge the parent items into the items array.
$this->items = array_merge( $this->items, array_reverse( $parents ) );
}
Expand full source code Collapse full source code View on Trac
Changelog
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |