Permalink
Browse files

Add support for attachment parent post hierarchy in the breadcrumb tr…

…ail with custom post types.

The need for an OOP approach to this is even more evident now.
  • Loading branch information...
1 parent 5861573 commit 6c232daaeb8b9d03c04e7663267a407aa83d475b @justintadlock committed Sep 21, 2012
Showing with 27 additions and 0 deletions.
  1. +27 −0 extensions/breadcrumb-trail.php
@@ -202,6 +202,33 @@ function breadcrumb_trail_get_items( $args = array() ) {
/* 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 ) );
}
+
+ /* Custom post types. */
+ elseif ( 'page' !== $parent_post_type ) {
+
+ $parent_post_type_object = get_post_type_object( $parent_post_type );
+
+ /* If $front has been set, add it to the $path. */
+ if ( $parent_post_type_object->rewrite['with_front'] && $wp_rewrite->front )
+ $path .= trailingslashit( $wp_rewrite->front );
+
+ /* If there's a slug, add it to the $path. */
+ if ( !empty( $parent_post_type_object->rewrite['slug'] ) )
+ $path .= $parent_post_type_object->rewrite['slug'];
+
+ /* If there's a path, check for parents. */
+ if ( !empty( $path ) )
+ $trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) );
+
+ /* If there's an archive page, add it to the trail. */
+ if ( !empty( $parent_post_type_object->has_archive ) ) {
+
+ /* Add support for a non-standard label of 'archive_title' (special use case). */
+ $label = !empty( $parent_post_type_object->labels->archive_title ) ? $parent_post_type_object->labels->archive_title : $parent_post_type_object->labels->name;
+
+ $trail[] = '<a href="' . get_post_type_archive_link( $parent_post_type ) . '" title="' . esc_attr( $label ) . '">' . $label . '</a>';
+ }
+ }
}
}

0 comments on commit 6c232da

Please sign in to comment.