Permalink
Browse files

Only check attachment trail if the attachment has a parent.

  • Loading branch information...
1 parent c92ce44 commit 90b3c10b419efbb676bd65bcaa91ccb01c17748e @justintadlock committed Sep 21, 2012
Showing with 14 additions and 7 deletions.
  1. +14 −7 extensions/breadcrumb-trail.php
@@ -171,15 +171,22 @@ function breadcrumb_trail_get_items( $args = array() ) {
/* If viewing a singular 'attachment'. */
elseif ( 'attachment' == $post_type ) {
- /* If $front has been set, add it to the $path. */
- $path .= trailingslashit( $wp_rewrite->front );
+ /* Get the parent post ID. */
+ $parent_id = $post->post_parent;
- /* If there's a path, check for parents. */
- if ( !empty( $path ) )
- $trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) );
+ /* If the attachment has a parent (attached to a post). */
+ if ( 0 < $parent_id ) {
- /* Map the post (parent) permalink structure tags to actual links. */
- $trail = array_merge( $trail, breadcrumb_trail_map_rewrite_tags( $post->post_parent, get_option( 'permalink_structure' ), $args ) );
+ /* If $front has been set, add it to the $path. */
+ $path .= trailingslashit( $wp_rewrite->front );
+
+ /* If there's a path, check for parents. */
+ if ( !empty( $path ) )
+ $trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) );
+
+ /* Map the post (parent) permalink structure tags to actual links. */
+ $trail = array_merge( $trail, breadcrumb_trail_map_rewrite_tags( $post->post_parent, get_option( 'permalink_structure' ), $args ) );
+ }
}
/* If a custom post type, check if there are any pages in its hierarchy based on the slug. */

0 comments on commit 90b3c10

Please sign in to comment.