Breadcrumb Trail - Version 0.4.1

Version Description

Download this release

Release Info

Developer greenshady
Plugin Icon 128x128 Breadcrumb Trail
Version 0.4.1
Comparing to
See all releases

Code changes from version 0.4 to 0.4.1

Files changed (2) hide show
  1. breadcrumb-trail.php +27 -25
  2. readme.txt +7 -2
breadcrumb-trail.php CHANGED
@@ -3,7 +3,7 @@
3
* Plugin Name: Breadcrumb Trail
4
* Plugin URI: http://justintadlock.com/archives/2009/04/05/breadcrumb-trail-wordpress-plugin
5
* Description: A WordPress plugin that gives you the <code>breadcrumb_trail()</code> template tag to use anywhere in your theme to show a breadcrumb menu.
6
- * Version: 0.4
7
* Author: Justin Tadlock
8
* Author URI: http://justintadlock.com
9
*
@@ -21,9 +21,9 @@
21
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22
*
23
* @package BreadcrumbTrail
24
- * @version 0.4.0
25
* @author Justin Tadlock <justin@justintadlock.com>
26
- * @copyright Copyright (c) 2008 - 2010, Justin Tadlock
27
* @link http://justintadlock.com/archives/2009/04/05/breadcrumb-trail-wordpress-plugin
28
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
29
*/
@@ -48,7 +48,6 @@ load_plugin_textdomain( 'breadcrumb-trail', false, 'breadcrumb-trail' );
48
* @return string Output of the breadcrumb menu.
49
*/
50
function breadcrumb_trail( $args = array() ) {
51
- global $wp_query;
52
53
/* Get the textdomain. */
54
$textdomain = breadcrumb_trail_textdomain();
@@ -67,8 +66,10 @@ function breadcrumb_trail( $args = array() ) {
67
);
68
69
/* Allow singular post views to have a taxonomy's terms prefixing the trail. */
70
- if ( is_singular() )
71
- $defaults["singular_{$wp_query->post->post_type}_taxonomy"] = false;
72
73
/* Apply filters to the arguments. */
74
$args = apply_filters( 'breadcrumb_trail_args', $args );
@@ -106,7 +107,7 @@ function breadcrumb_trail( $args = array() ) {
106
}
107
108
/* Allow developers to filter the breadcrumb trail HTML. */
109
- $breadcrumb = apply_filters( 'breadcrumb_trail', $breadcrumb );
110
111
/* Output the breadcrumb. */
112
if ( $args['echo'] )
@@ -126,7 +127,7 @@ function breadcrumb_trail( $args = array() ) {
126
* @return array List of items to be shown in the trail.
127
*/
128
function breadcrumb_trail_get_items( $args = array() ) {
129
- global $wp_query, $wp_rewrite;
130
131
/* Get the textdomain. */
132
$textdomain = breadcrumb_trail_textdomain();
@@ -147,7 +148,7 @@ function breadcrumb_trail_get_items( $args = array() ) {
147
148
/* If viewing the "home"/posts page. */
149
elseif ( is_home() ) {
150
- $home_page = get_page( $wp_query->get_queried_object_id() );
151
$trail = array_merge( $trail, breadcrumb_trail_get_parents( $home_page->post_parent, '' ) );
152
$trail['trail_end'] = get_the_title( $home_page->ID );
153
}
@@ -156,8 +157,8 @@ function breadcrumb_trail_get_items( $args = array() ) {
156
elseif ( is_singular() ) {
157
158
/* Get singular post variables needed. */
159
- $post = $wp_query->get_queried_object();
160
- $post_id = absint( $wp_query->get_queried_object_id() );
161
$post_type = $post->post_type;
162
$parent = absint( $post->post_parent );
163
@@ -175,7 +176,7 @@ function breadcrumb_trail_get_items( $args = array() ) {
175
$trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) );
176
177
/* Map the permalink structure tags to actual links. */
178
- $trail = array_merge( $trail, breadcrumb_trail_map_rewrite_tags( $post_id, get_option( 'permalink_structure' ) ) );
179
}
180
181
/* If viewing a singular 'attachment'. */
@@ -189,7 +190,7 @@ function breadcrumb_trail_get_items( $args = array() ) {
189
$trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) );
190
191
/* Map the post (parent) permalink structure tags to actual links. */
192
- $trail = array_merge( $trail, breadcrumb_trail_map_rewrite_tags( $post->post_parent, get_option( 'permalink_structure' ) ) );
193
}
194
195
/* If a custom post type, check if there are any pages in its hierarchy based on the slug. */
@@ -208,7 +209,7 @@ function breadcrumb_trail_get_items( $args = array() ) {
208
$trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) );
209
210
/* If there's an archive page, add it to the trail. */
211
- if ( !empty( $post_type_object->rewrite['archive'] ) && function_exists( 'get_post_type_archive_link' ) )
212
$trail[] = '<a href="' . get_post_type_archive_link( $post_type ) . '" title="' . esc_attr( $post_type_object->labels->name ) . '">' . $post_type_object->labels->name . '</a>';
213
}
214
@@ -237,7 +238,7 @@ function breadcrumb_trail_get_items( $args = array() ) {
237
if ( is_tax() || is_category() || is_tag() ) {
238
239
/* Get some taxonomy and term variables. */
240
- $term = $wp_query->get_queried_object();
241
$taxonomy = get_taxonomy( $term->taxonomy );
242
243
/* Get the path to the term archive. Use this to determine if a page is present with it. */
@@ -260,14 +261,11 @@ function breadcrumb_trail_get_items( $args = array() ) {
260
$trail = array_merge( $trail, breadcrumb_trail_get_term_parents( $term->parent, $term->taxonomy ) );
261
262
/* Add the term name to the trail end. */
263
- if ( function_exists( 'single_term_title' ) )
264
- $trail['trail_end'] = single_term_title( '', false );
265
- else
266
- $trail['trail_end'] = $term->name;
267
}
268
269
/* If viewing a post type archive. */
270
- elseif ( function_exists( 'is_post_type_archive' ) && is_post_type_archive() ) {
271
272
/* Get the post type object. */
273
$post_type_object = get_post_type_object( get_query_var( 'post_type' ) );
@@ -277,8 +275,8 @@ function breadcrumb_trail_get_items( $args = array() ) {
277
$path .= trailingslashit( $wp_rewrite->front );
278
279
/* If there's a slug, add it to the $path. */
280
- if ( !empty( $post_type_object->rewrite['archive'] ) )
281
- $path .= $post_type_object->rewrite['archive'];
282
283
/* If there's a path, check for parents. */
284
if ( !empty( $path ) )
@@ -358,7 +356,7 @@ function breadcrumb_trail_get_items( $args = array() ) {
358
$trail['trail_end'] = __( '404 Not Found', $textdomain );
359
360
/* Allow devs to step in and filter the $trail array. */
361
- return apply_filters( 'breadcrumb_trail_items', $trail );
362
}
363
364
/**
@@ -370,9 +368,10 @@ function breadcrumb_trail_get_items( $args = array() ) {
370
* @since 0.4.0
371
* @param int $post_id ID of the post whose parents we want.
372
* @param string $path Path of a potential parent page.
373
* @return array $trail Array of links to the post breadcrumb.
374
*/
375
- function breadcrumb_trail_map_rewrite_tags( $post_id = '', $path = '' ) {
376
377
/* Set up an empty $trail array. */
378
$trail = array();
@@ -423,7 +422,7 @@ function breadcrumb_trail_map_rewrite_tags( $post_id = '', $path = '' ) {
423
$trail[] = '<a href="' . get_author_posts_url( $post->post_author ) . '" title="' . esc_attr( get_the_author_meta( 'display_name', $post->post_author ) ) . '">' . get_the_author_meta( 'display_name', $post->post_author ) . '</a>';
424
425
/* If using the %category% tag, add a link to the first category archive to match permalinks. */
426
- elseif ( '%category%' == $tag ) {
427
428
/* Get the post categories. */
429
$terms = get_the_category( $post_id );
@@ -465,6 +464,9 @@ function breadcrumb_trail_get_parents( $post_id = '', $path = '' ) {
465
/* Set up an empty trail array. */
466
$trail = array();
467
468
/* If neither a post ID nor path set, return an empty array. */
469
if ( empty( $post_id ) && empty( $path ) )
470
return $trail;
3
* Plugin Name: Breadcrumb Trail
4
* Plugin URI: http://justintadlock.com/archives/2009/04/05/breadcrumb-trail-wordpress-plugin
5
* Description: A WordPress plugin that gives you the <code>breadcrumb_trail()</code> template tag to use anywhere in your theme to show a breadcrumb menu.
6
+ * Version: 0.4.1
7
* Author: Justin Tadlock
8
* Author URI: http://justintadlock.com
9
*
21
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22
*
23
* @package BreadcrumbTrail
24
+ * @version 0.4.1
25
* @author Justin Tadlock <justin@justintadlock.com>
26
+ * @copyright Copyright (c) 2008 - 2011, Justin Tadlock
27
* @link http://justintadlock.com/archives/2009/04/05/breadcrumb-trail-wordpress-plugin
28
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
29
*/
48
* @return string Output of the breadcrumb menu.
49
*/
50
function breadcrumb_trail( $args = array() ) {
51
52
/* Get the textdomain. */
53
$textdomain = breadcrumb_trail_textdomain();
66
);
67
68
/* Allow singular post views to have a taxonomy's terms prefixing the trail. */
69
+ if ( is_singular() ) {
70
+ $post = get_queried_object();
71
+ $defaults["singular_{$post->post_type}_taxonomy"] = false;
72
+ }
73
74
/* Apply filters to the arguments. */
75
$args = apply_filters( 'breadcrumb_trail_args', $args );
107
}
108
109
/* Allow developers to filter the breadcrumb trail HTML. */
110
+ $breadcrumb = apply_filters( 'breadcrumb_trail', $breadcrumb, $args );
111
112
/* Output the breadcrumb. */
113
if ( $args['echo'] )
127
* @return array List of items to be shown in the trail.
128
*/
129
function breadcrumb_trail_get_items( $args = array() ) {
130
+ global $wp_rewrite;
131
132
/* Get the textdomain. */
133
$textdomain = breadcrumb_trail_textdomain();
148
149
/* If viewing the "home"/posts page. */
150
elseif ( is_home() ) {
151
+ $home_page = get_page( get_queried_object_id() );
152
$trail = array_merge( $trail, breadcrumb_trail_get_parents( $home_page->post_parent, '' ) );
153
$trail['trail_end'] = get_the_title( $home_page->ID );
154
}
157
elseif ( is_singular() ) {
158
159
/* Get singular post variables needed. */
160
+ $post = get_queried_object();
161
+ $post_id = absint( get_queried_object_id() );
162
$post_type = $post->post_type;
163
$parent = absint( $post->post_parent );
164
176
$trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) );
177
178
/* Map the permalink structure tags to actual links. */
179
+ $trail = array_merge( $trail, breadcrumb_trail_map_rewrite_tags( $post_id, get_option( 'permalink_structure' ), $args ) );
180
}
181
182
/* If viewing a singular 'attachment'. */
190
$trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) );
191
192
/* Map the post (parent) permalink structure tags to actual links. */
193
+ $trail = array_merge( $trail, breadcrumb_trail_map_rewrite_tags( $post->post_parent, get_option( 'permalink_structure' ), $args ) );
194
}
195
196
/* If a custom post type, check if there are any pages in its hierarchy based on the slug. */
209
$trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) );
210
211
/* If there's an archive page, add it to the trail. */
212
+ if ( !empty( $post_type_object->has_archive ) )
213
$trail[] = '<a href="' . get_post_type_archive_link( $post_type ) . '" title="' . esc_attr( $post_type_object->labels->name ) . '">' . $post_type_object->labels->name . '</a>';
214
}
215
238
if ( is_tax() || is_category() || is_tag() ) {
239
240
/* Get some taxonomy and term variables. */
241
+ $term = get_queried_object();
242
$taxonomy = get_taxonomy( $term->taxonomy );
243
244
/* Get the path to the term archive. Use this to determine if a page is present with it. */
261
$trail = array_merge( $trail, breadcrumb_trail_get_term_parents( $term->parent, $term->taxonomy ) );
262
263
/* Add the term name to the trail end. */
264
+ $trail['trail_end'] = single_term_title( '', false );
265
}
266
267
/* If viewing a post type archive. */
268
+ elseif ( is_post_type_archive() ) {
269
270
/* Get the post type object. */
271
$post_type_object = get_post_type_object( get_query_var( 'post_type' ) );
275
$path .= trailingslashit( $wp_rewrite->front );
276
277
/* If there's a slug, add it to the $path. */
278
+ if ( !empty( $post_type_object->rewrite['slug'] ) )
279
+ $path .= $post_type_object->rewrite['slug'];
280
281
/* If there's a path, check for parents. */
282
if ( !empty( $path ) )
356
$trail['trail_end'] = __( '404 Not Found', $textdomain );
357
358
/* Allow devs to step in and filter the $trail array. */
359
+ return apply_filters( 'breadcrumb_trail_items', $trail, $args );
360
}
361
362
/**
368
* @since 0.4.0
369
* @param int $post_id ID of the post whose parents we want.
370
* @param string $path Path of a potential parent page.
371
+ * @param array $args Mixed arguments for the menu.
372
* @return array $trail Array of links to the post breadcrumb.
373
*/
374
+ function breadcrumb_trail_map_rewrite_tags( $post_id = '', $path = '', $args = array() ) {
375
376
/* Set up an empty $trail array. */
377
$trail = array();
422
$trail[] = '<a href="' . get_author_posts_url( $post->post_author ) . '" title="' . esc_attr( get_the_author_meta( 'display_name', $post->post_author ) ) . '">' . get_the_author_meta( 'display_name', $post->post_author ) . '</a>';
423
424
/* If using the %category% tag, add a link to the first category archive to match permalinks. */
425
+ elseif ( '%category%' == $tag && 'category' !== $args["singular_{$post->post_type}_taxonomy"] ) {
426
427
/* Get the post categories. */
428
$terms = get_the_category( $post_id );
464
/* Set up an empty trail array. */
465
$trail = array();
466
467
+ /* Trim '/' off $path in case we just got a simple '/' instead of a real path. */
468
+ $path = trim( $path, '/' );
469
+
470
/* If neither a post ID nor path set, return an empty array. */
471
if ( empty( $post_id ) && empty( $path ) )
472
return $trail;
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: greenshady
3
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3687060
4
Tags: navigation, menu, breadcrumb, breadcrumbs
5
Requires at least: 3.1
6
- Tested up to: 3.1
7
- Stable tag: 0.4
8
9
An easy-to-use template tag for showing a breadcrumb menu on your site.
10
@@ -56,6 +56,11 @@ There are no screenshots for this plugin.
56
57
== Changelog ==
58
59
**Version 0.4.0**
60
61
* New function: `breadcrumb_trail_get_items()`, which grabs a list of all the trail items. This separates the items from the main `breadcrumb_trail()` function.
3
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3687060
4
Tags: navigation, menu, breadcrumb, breadcrumbs
5
Requires at least: 3.1
6
+ Tested up to: 3.2.1
7
+ Stable tag: 0.4.1
8
9
An easy-to-use template tag for showing a breadcrumb menu on your site.
10
56
57
== Changelog ==
58
59
+ **Version 0.4.1**
60
+
61
+ * Use `get_queried_object()` and `get_queried_object_id()` instead of accessing `$wp_query` directly.
62
+ * Pass `$args` as second parameter in `breadcrumb_trail` hook.
63
+
64
**Version 0.4.0**
65
66
* New function: `breadcrumb_trail_get_items()`, which grabs a list of all the trail items. This separates the items from the main `breadcrumb_trail()` function.