Skip to content

Commit

Permalink
Fix for handling the posts page and/or the rewrite front for a single…
Browse files Browse the repository at this point in the history
… post view. There were some scenarios where we had conflicts with the best way to handle this. We may need to revisit this commit in the future and find a better path forward if we run into situations where this is not correct. For the majority of use cases, it should be.
  • Loading branch information
justintadlock committed Oct 18, 2018
1 parent e152533 commit 573649a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/Build/Path.php
Expand Up @@ -55,6 +55,9 @@ public function make() {
// If the path is a post, run the parent crumbs and bail early.
if ( $post ) {
$this->breadcrumbs->build( 'PostAncestors', [ 'post' => $post ] );

$this->breadcrumbs->crumb( 'Post', [ 'post' => $post ] );

return;
}

Expand All @@ -74,14 +77,18 @@ public function make() {
// Get the parent post by the given path.
$post = get_page_by_path( $slug );

// If a parent post is found, set the $post_id
// If a parent post is found, build the crumbs
// and break out of the loop.
if ( ! empty( $post ) && 0 < $post->ID ) {

$this->breadcrumbs->build( 'PostAncestors', [
'post' => $post
] );

$this->breadcrumbs->crumb( 'Post', [
'post' => $post
] );

break;

// If the slug matches a post type, let's build
Expand Down
15 changes: 12 additions & 3 deletions src/Build/PostType.php
Expand Up @@ -38,6 +38,7 @@ class PostType extends Base {
* @return void
*/
public function make() {
global $wp_rewrite;

if ( ! post_type_exists( $this->post_type ) ) {
return;
Expand All @@ -52,9 +53,17 @@ public function make() {
// Add post crumb if we have a posts page.
if ( 'posts' !== $show_on_front && 0 < $post_id ) {

$this->breadcrumbs->crumb( 'Post', [
'post' => get_post( $post_id )
] );
$post = get_post( $post_id );

// If the posts page is the same as the rewrite
// front path, we should've already handled that
// scenario at this point.
if ( trim( $wp_rewrite->front, '/' ) !== $post->post_name ) {

$this->breadcrumbs->crumb( 'Post', [
'post' => $post
] );
}
}

return;
Expand Down
3 changes: 0 additions & 3 deletions src/Query/PostTypeArchive.php
Expand Up @@ -37,9 +37,6 @@ public function make() {
// Add site home crumb.
$this->breadcrumbs->crumb( 'Home' );

// Build rewrite front crumbs.
$this->breadcrumbs->build( 'RewriteFront' );

// Get the post type object.
$type = get_post_type_object( get_query_var( 'post_type' ) );

Expand Down

0 comments on commit 573649a

Please sign in to comment.