Breadcrumb Trail - Version 0.4

Version Description

Download this release

Release Info

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

Code changes from version 0.3.2 to 0.4

breadcrumb-trail-en_EN.mo CHANGED
Binary file
breadcrumb-trail-en_EN.po CHANGED
@@ -2,7 +2,7 @@ msgid ""
2
  msgstr ""
3
  "Project-Id-Version: Breadcrumb Trail WordPress Plugin\n"
4
  "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2010-10-24 09:26-0600\n"
6
  "PO-Revision-Date: \n"
7
  "Last-Translator: Justin Tadlock <justin@justintadlock.com>\n"
8
  "Language-Team: <justin@justintadlock.com>\n"
@@ -15,62 +15,73 @@ msgstr ""
15
  "X-Poedit-Basepath: .\n"
16
  "X-Poedit-SearchPath-0: .\n"
17
 
18
- #: breadcrumb-trail.php:55
19
  msgid "Browse:"
20
  msgstr ""
21
 
22
- #: breadcrumb-trail.php:58
23
  msgid "Home"
24
  msgstr ""
25
 
26
- #: breadcrumb-trail.php:219
27
  msgid "g:i a"
28
  msgstr ""
29
 
30
- #: breadcrumb-trail.php:222
31
  #, php-format
32
  msgid "Minute %1$s"
33
  msgstr ""
34
 
35
- #: breadcrumb-trail.php:222
36
  msgid "i"
37
  msgstr ""
38
 
39
- #: breadcrumb-trail.php:225
40
  msgid "g a"
41
  msgstr ""
42
 
43
- #: breadcrumb-trail.php:236
44
- #: breadcrumb-trail.php:242
45
- #: breadcrumb-trail.php:247
46
- #: breadcrumb-trail.php:252
 
47
  msgid "Y"
48
  msgstr ""
49
 
50
- #: breadcrumb-trail.php:237
51
- #: breadcrumb-trail.php:248
 
52
  msgid "F"
53
  msgstr ""
54
 
55
- #: breadcrumb-trail.php:238
56
- msgid "j"
 
57
  msgstr ""
58
 
59
- #: breadcrumb-trail.php:243
60
  #, php-format
61
  msgid "Week %1$s"
62
  msgstr ""
63
 
64
- #: breadcrumb-trail.php:243
65
  msgid "W"
66
  msgstr ""
67
 
68
- #: breadcrumb-trail.php:259
69
  #, php-format
70
  msgid "Search results for &quot;%1$s&quot;"
71
  msgstr ""
72
 
73
- #: breadcrumb-trail.php:263
74
  msgid "404 Not Found"
75
  msgstr ""
76
 
 
 
 
 
 
 
 
 
2
  msgstr ""
3
  "Project-Id-Version: Breadcrumb Trail WordPress Plugin\n"
4
  "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2011-03-19 15:52-0600\n"
6
  "PO-Revision-Date: \n"
7
  "Last-Translator: Justin Tadlock <justin@justintadlock.com>\n"
8
  "Language-Team: <justin@justintadlock.com>\n"
15
  "X-Poedit-Basepath: .\n"
16
  "X-Poedit-SearchPath-0: .\n"
17
 
18
+ #: breadcrumb-trail.php:62
19
  msgid "Browse:"
20
  msgstr ""
21
 
22
+ #: breadcrumb-trail.php:65
23
  msgid "Home"
24
  msgstr ""
25
 
26
+ #: breadcrumb-trail.php:314
27
  msgid "g:i a"
28
  msgstr ""
29
 
30
+ #: breadcrumb-trail.php:317
31
  #, php-format
32
  msgid "Minute %1$s"
33
  msgstr ""
34
 
35
+ #: breadcrumb-trail.php:317
36
  msgid "i"
37
  msgstr ""
38
 
39
+ #: breadcrumb-trail.php:320
40
  msgid "g a"
41
  msgstr ""
42
 
43
+ #: breadcrumb-trail.php:331
44
+ #: breadcrumb-trail.php:337
45
+ #: breadcrumb-trail.php:342
46
+ #: breadcrumb-trail.php:347
47
+ #: breadcrumb-trail.php:411
48
  msgid "Y"
49
  msgstr ""
50
 
51
+ #: breadcrumb-trail.php:332
52
+ #: breadcrumb-trail.php:343
53
+ #: breadcrumb-trail.php:415
54
  msgid "F"
55
  msgstr ""
56
 
57
+ #: breadcrumb-trail.php:333
58
+ #: breadcrumb-trail.php:419
59
+ msgid "d"
60
  msgstr ""
61
 
62
+ #: breadcrumb-trail.php:338
63
  #, php-format
64
  msgid "Week %1$s"
65
  msgstr ""
66
 
67
+ #: breadcrumb-trail.php:338
68
  msgid "W"
69
  msgstr ""
70
 
71
+ #: breadcrumb-trail.php:354
72
  #, php-format
73
  msgid "Search results for &quot;%1$s&quot;"
74
  msgstr ""
75
 
76
+ #: breadcrumb-trail.php:358
77
  msgid "404 Not Found"
78
  msgstr ""
79
 
80
+ #: breadcrumb-trail.php:415
81
+ msgid "F Y"
82
+ msgstr ""
83
+
84
+ #: breadcrumb-trail.php:419
85
+ msgid "F j, Y"
86
+ msgstr ""
87
+
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.3.2
7
  * Author: Justin Tadlock
8
  * Author URI: http://justintadlock.com
9
  *
@@ -21,7 +21,7 @@
21
  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22
  *
23
  * @package BreadcrumbTrail
24
- * @version 0.3.2
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
@@ -29,36 +29,33 @@
29
  */
30
 
31
  /**
32
- * Yes, we're localizing the plugin. This partly makes sure non-English
33
- * users can use it too. To translate into your language use the
34
- * en_EN.po file as as guide. Poedit is a good tool to for translating.
35
  * @link http://poedit.net
36
  *
37
- * @since 0.1
38
  */
39
  load_plugin_textdomain( 'breadcrumb-trail', false, 'breadcrumb-trail' );
40
 
41
  /**
42
- * Shows a breadcrumb for all types of pages. Themes and plugins can filter $args or input directly.
43
- * Allow filtering of only the $args using get_the_breadcrumb_args.
 
44
  *
45
- * @since 0.1
46
  * @param array $args Mixed arguments for the menu.
47
  * @return string Output of the breadcrumb menu.
48
  */
49
  function breadcrumb_trail( $args = array() ) {
50
- global $wp_query, $wp_rewrite;
51
 
52
  /* Get the textdomain. */
53
- $textdomain = 'breadcrumb-trail';
54
 
55
  /* Create an empty variable for the breadcrumb. */
56
  $breadcrumb = '';
57
 
58
- /* Create an empty array for the trail. */
59
- $trail = array();
60
- $path = '';
61
-
62
  /* Set up the default arguments for the breadcrumb. */
63
  $defaults = array(
64
  'separator' => '/',
@@ -66,7 +63,6 @@ function breadcrumb_trail( $args = array() ) {
66
  'after' => false,
67
  'front_page' => true,
68
  'show_home' => __( 'Home', $textdomain ),
69
- 'single_tax' => null, // @deprecated 0.3 Use singular_{$post_type}_taxonomy.
70
  'echo' => true
71
  );
72
 
@@ -78,22 +74,75 @@ function breadcrumb_trail( $args = array() ) {
78
  $args = apply_filters( 'breadcrumb_trail_args', $args );
79
 
80
  /* Parse the arguments and extract them for easy variable naming. */
81
- extract( wp_parse_args( $args, $defaults ) );
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
- /* For backwards compatibility, set $single_tax if it's explicitly given. */
84
- if ( !is_null( $single_tax ) )
85
- $args['singular_post_taxonomy'] = $single_tax;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  /* If $show_home is set and we're not on the front page of the site, link to the home page. */
88
- if ( !is_front_page() && $show_home )
89
- $trail[] = '<a href="' . home_url() . '" title="' . esc_attr( get_bloginfo( 'name' ) ) . '" rel="home" class="trail-begin">' . $show_home . '</a>';
90
 
91
  /* If viewing the front page of the site. */
92
  if ( is_front_page() ) {
93
- if ( !$front_page )
94
- $trail = false;
95
- elseif ( $show_home )
96
- $trail['trail_end'] = "{$show_home}";
97
  }
98
 
99
  /* If viewing the "home"/posts page. */
@@ -110,15 +159,44 @@ function breadcrumb_trail( $args = array() ) {
110
  $post = $wp_query->get_queried_object();
111
  $post_id = absint( $wp_query->get_queried_object_id() );
112
  $post_type = $post->post_type;
113
- $parent = $post->post_parent;
114
 
115
- /* If a custom post type, check if there are any pages in its hierarchy based on the slug. */
116
- if ( 'page' !== $post_type ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
- $post_type_object = get_post_type_object( $post_type );
 
119
 
120
  /* If $front has been set, add it to the $path. */
121
- if ( 'post' == $post_type || 'attachment' == $post_type || ( $post_type_object->rewrite['with_front'] && $wp_rewrite->front ) )
122
  $path .= trailingslashit( $wp_rewrite->front );
123
 
124
  /* If there's a slug, add it to the $path. */
@@ -135,11 +213,15 @@ function breadcrumb_trail( $args = array() ) {
135
  }
136
 
137
  /* If the post type path returns nothing and there is a parent, get its parents. */
138
- if ( empty( $path ) && 0 !== $parent || 'attachment' == $post_type )
 
 
 
 
139
  $trail = array_merge( $trail, breadcrumb_trail_get_parents( $parent, '' ) );
140
 
141
  /* Display terms for specific post type taxonomy if requested. */
142
- if ( isset( $args["singular_{$post_type}_taxonomy"] ) && $terms = get_the_term_list( $post_id, $args["singular_{$post_type}_taxonomy"], '', ', ', '' ) )
143
  $trail[] = $terms;
144
 
145
  /* End with the post title. */
@@ -178,7 +260,10 @@ function breadcrumb_trail( $args = array() ) {
178
  $trail = array_merge( $trail, breadcrumb_trail_get_term_parents( $term->parent, $term->taxonomy ) );
179
 
180
  /* Add the term name to the trail end. */
181
- $trail['trail_end'] = $term->name;
 
 
 
182
  }
183
 
184
  /* If viewing a post type archive. */
@@ -245,7 +330,7 @@ function breadcrumb_trail( $args = array() ) {
245
  if ( is_day() ) {
246
  $trail[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . get_the_time( esc_attr__( 'Y', $textdomain ) ) . '">' . get_the_time( __( 'Y', $textdomain ) ) . '</a>';
247
  $trail[] = '<a href="' . get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) . '" title="' . get_the_time( esc_attr__( 'F', $textdomain ) ) . '">' . get_the_time( __( 'F', $textdomain ) ) . '</a>';
248
- $trail['trail_end'] = get_the_time( __( 'j', $textdomain ) );
249
  }
250
 
251
  elseif ( get_query_var( 'w' ) ) {
@@ -272,43 +357,97 @@ function breadcrumb_trail( $args = array() ) {
272
  elseif ( is_404() )
273
  $trail['trail_end'] = __( '404 Not Found', $textdomain );
274
 
275
- /* Connect the breadcrumb trail if there are items in the trail. */
276
- if ( is_array( $trail ) ) {
 
277
 
278
- /* Open the breadcrumb trail containers. */
279
- $breadcrumb = '<div class="breadcrumb breadcrumbs"><div class="breadcrumb-trail">';
 
 
 
 
 
 
 
 
 
 
280
 
281
- /* If $before was set, wrap it in a container. */
282
- if ( !empty( $before ) )
283
- $breadcrumb .= '<span class="trail-before">' . $before . '</span> ';
284
 
285
- /* Wrap the $trail['trail_end'] value in a container. */
286
- if ( !empty( $trail['trail_end'] ) )
287
- $trail['trail_end'] = '<span class="trail-end">' . $trail['trail_end'] . '</span>';
288
 
289
- /* Format the separator. */
290
- if ( !empty( $separator ) )
291
- $separator = '<span class="sep">' . $separator . '</span>';
292
 
293
- /* Join the individual trail items into a single string. */
294
- $breadcrumb .= join( " {$separator} ", $trail );
 
295
 
296
- /* If $after was set, wrap it in a container. */
297
- if ( !empty( $after ) )
298
- $breadcrumb .= ' <span class="trail-after">' . $after . '</span>';
299
 
300
- /* Close the breadcrumb trail containers. */
301
- $breadcrumb .= '</div></div>';
302
- }
303
 
304
- /* Allow developers to filter the breadcrumb trail HTML. */
305
- $breadcrumb = apply_filters( 'breadcrumb_trail', $breadcrumb );
306
 
307
- /* Output the breadcrumb. */
308
- if ( $echo )
309
- echo $breadcrumb;
310
- else
311
- return $breadcrumb;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
312
  }
313
 
314
  /**
@@ -316,7 +455,7 @@ function breadcrumb_trail( $args = array() ) {
316
  * a clear path back to home given what would normally be a "ghost" directory. If any page matches the given
317
  * path, it'll be added. But, it's also just a way to check for a hierarchy with hierarchical post types.
318
  *
319
- * @since 0.3
320
  * @param int $post_id ID of the post whose parents we want.
321
  * @param string $path Path of a potential parent page.
322
  * @return array $trail Array of parent page links.
@@ -399,7 +538,7 @@ function breadcrumb_trail_get_parents( $post_id = '', $path = '' ) {
399
  * Searches for term parents of hierarchical taxonomies. This function is similar to the WordPress
400
  * function get_category_parents() but handles any type of taxonomy.
401
  *
402
- * @since 0.3
403
  * @param int $parent_id The ID of the first parent.
404
  * @param object|string $taxonomy The taxonomy of the term whose parents we want.
405
  * @return array $trail Array of links to parent terms.
@@ -435,4 +574,14 @@ function breadcrumb_trail_get_term_parents( $parent_id = '', $taxonomy = '' ) {
435
  return $trail;
436
  }
437
 
 
 
 
 
 
 
 
 
 
 
438
  ?>
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
  * 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
29
  */
30
 
31
  /**
32
+ * Yes, we're localizing the plugin. This partly makes sure non-English users can use it too.
33
+ * To translate into your language use the breadcrumb-trail-en_EN.po file as as guide. Poedit
34
+ * is a good tool to for translating.
35
  * @link http://poedit.net
36
  *
37
+ * @since 0.1.0
38
  */
39
  load_plugin_textdomain( 'breadcrumb-trail', false, 'breadcrumb-trail' );
40
 
41
  /**
42
+ * Shows a breadcrumb for all types of pages. This function is formatting the final output of the
43
+ * breadcrumb trail. The breadcrumb_trail_get_items() function returns the items and this function
44
+ * formats those items.
45
  *
46
+ * @since 0.1.0
47
  * @param array $args Mixed arguments for the menu.
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();
55
 
56
  /* Create an empty variable for the breadcrumb. */
57
  $breadcrumb = '';
58
 
 
 
 
 
59
  /* Set up the default arguments for the breadcrumb. */
60
  $defaults = array(
61
  'separator' => '/',
63
  'after' => false,
64
  'front_page' => true,
65
  'show_home' => __( 'Home', $textdomain ),
 
66
  'echo' => true
67
  );
68
 
74
  $args = apply_filters( 'breadcrumb_trail_args', $args );
75
 
76
  /* Parse the arguments and extract them for easy variable naming. */
77
+ $args = wp_parse_args( $args, $defaults );
78
+
79
+ /* Get the trail items. */
80
+ $trail = breadcrumb_trail_get_items( $args );
81
+
82
+ /* Connect the breadcrumb trail if there are items in the trail. */
83
+ if ( !empty( $trail ) && is_array( $trail ) ) {
84
+
85
+ /* Open the breadcrumb trail containers. */
86
+ $breadcrumb = '<div class="breadcrumb breadcrumbs"><div class="breadcrumb-trail">';
87
+
88
+ /* If $before was set, wrap it in a container. */
89
+ $breadcrumb .= ( !empty( $args['before'] ) ? '<span class="trail-before">' . $args['before'] . '</span> ' : '' );
90
 
91
+ /* Wrap the $trail['trail_end'] value in a container. */
92
+ if ( !empty( $trail['trail_end'] ) )
93
+ $trail['trail_end'] = '<span class="trail-end">' . $trail['trail_end'] . '</span>';
94
+
95
+ /* Format the separator. */
96
+ $separator = ( !empty( $args['separator'] ) ? '<span class="sep">' . $args['separator'] . '</span>' : '<span class="sep">/</span>' );
97
+
98
+ /* Join the individual trail items into a single string. */
99
+ $breadcrumb .= join( " {$separator} ", $trail );
100
+
101
+ /* If $after was set, wrap it in a container. */
102
+ $breadcrumb .= ( !empty( $args['after'] ) ? ' <span class="trail-after">' . $args['after'] . '</span>' : '' );
103
+
104
+ /* Close the breadcrumb trail containers. */
105
+ $breadcrumb .= '</div></div>';
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'] )
113
+ echo $breadcrumb;
114
+ else
115
+ return $breadcrumb;
116
+ }
117
+
118
+ /**
119
+ * Gets the items for the breadcrumb trail. This is the heart of the script. It checks the current page
120
+ * being viewed and decided based on the information provided by WordPress what items should be
121
+ * added to the breadcrumb trail.
122
+ *
123
+ * @since 0.4.0
124
+ * @todo Build in caching based on the queried object ID.
125
+ * @param array $args Mixed arguments for the menu.
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();
133
+
134
+ /* Set up an empty trail array and empty path. */
135
+ $trail = array();
136
+ $path = '';
137
 
138
  /* If $show_home is set and we're not on the front page of the site, link to the home page. */
139
+ if ( !is_front_page() && $args['show_home'] )
140
+ $trail[] = '<a href="' . home_url() . '" title="' . esc_attr( get_bloginfo( 'name' ) ) . '" rel="home" class="trail-begin">' . $args['show_home'] . '</a>';
141
 
142
  /* If viewing the front page of the site. */
143
  if ( is_front_page() ) {
144
+ if ( $args['show_home'] && $args['front_page'] )
145
+ $trail['trail_end'] = "{$args['show_home']}";
 
 
146
  }
147
 
148
  /* If viewing the "home"/posts page. */
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
 
164
+ /* Get the post type object. */
165
+ $post_type_object = get_post_type_object( $post_type );
166
+
167
+ /* If viewing a singular 'post'. */
168
+ if ( 'post' == $post_type ) {
169
+
170
+ /* If $front has been set, add it to the $path. */
171
+ $path .= trailingslashit( $wp_rewrite->front );
172
+
173
+ /* If there's a path, check for parents. */
174
+ if ( !empty( $path ) )
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'. */
182
+ elseif ( 'attachment' == $post_type ) {
183
+
184
+ /* If $front has been set, add it to the $path. */
185
+ $path .= trailingslashit( $wp_rewrite->front );
186
+
187
+ /* If there's a path, check for parents. */
188
+ if ( !empty( $path ) )
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. */
196
+ elseif ( 'page' !== $post_type ) {
197
 
198
  /* If $front has been set, add it to the $path. */
199
+ if ( $post_type_object->rewrite['with_front'] && $wp_rewrite->front )
200
  $path .= trailingslashit( $wp_rewrite->front );
201
 
202
  /* If there's a slug, add it to the $path. */
213
  }
214
 
215
  /* If the post type path returns nothing and there is a parent, get its parents. */
216
+ if ( ( empty( $path ) && 0 !== $parent ) || ( 'attachment' == $post_type ) )
217
+ $trail = array_merge( $trail, breadcrumb_trail_get_parents( $parent, '' ) );
218
+
219
+ /* Or, if the post type is hierarchical and there's a parent, get its parents. */
220
+ elseif ( 0 !== $parent && is_post_type_hierarchical( $post_type ) )
221
  $trail = array_merge( $trail, breadcrumb_trail_get_parents( $parent, '' ) );
222
 
223
  /* Display terms for specific post type taxonomy if requested. */
224
+ if ( !empty( $args["singular_{$post_type}_taxonomy"] ) && $terms = get_the_term_list( $post_id, $args["singular_{$post_type}_taxonomy"], '', ', ', '' ) )
225
  $trail[] = $terms;
226
 
227
  /* End with the post title. */
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. */
330
  if ( is_day() ) {
331
  $trail[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . get_the_time( esc_attr__( 'Y', $textdomain ) ) . '">' . get_the_time( __( 'Y', $textdomain ) ) . '</a>';
332
  $trail[] = '<a href="' . get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) . '" title="' . get_the_time( esc_attr__( 'F', $textdomain ) ) . '">' . get_the_time( __( 'F', $textdomain ) ) . '</a>';
333
+ $trail['trail_end'] = get_the_time( __( 'd', $textdomain ) );
334
  }
335
 
336
  elseif ( get_query_var( 'w' ) ) {
357
  elseif ( is_404() )
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
+ /**
365
+ * Turns %tag% from permalink structures into usable links for the breadcrumb trail. This feels kind of
366
+ * hackish for now because we're checking for specific %tag% examples and only doing it for the 'post'
367
+ * post type. In the future, maybe it'll handle a wider variety of possibilities, especially for custom post
368
+ * types.
369
+ *
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();
 
379
 
380
+ /* Make sure there's a $path and $post_id before continuing. */
381
+ if ( empty( $path ) || empty( $post_id ) )
382
+ return $trail;
383
 
384
+ /* Get the post based on the post ID. */
385
+ $post = get_post( $post_id );
 
386
 
387
+ /* If no post is returned, an error is returned, or the post does not have a 'post' post type, return. */
388
+ if ( empty( $post ) || is_wp_error( $post ) || 'post' !== $post->post_type )
389
+ return $trail;
390
 
391
+ /* Get the textdomain. */
392
+ $textdomain = breadcrumb_trail_textdomain();
 
393
 
394
+ /* Trim '/' from both sides of the $path. */
395
+ $path = trim( $path, '/' );
 
396
 
397
+ /* Split the $path into an array of strings. */
398
+ $matches = explode( '/', $path );
399
 
400
+ /* If matches are found for the path. */
401
+ if ( is_array( $matches ) ) {
402
+
403
+ /* Loop through each of the matches, adding each to the $trail array. */
404
+ foreach ( $matches as $match ) {
405
+
406
+ /* Trim any '/' from the $match. */
407
+ $tag = trim( $match, '/' );
408
+
409
+ /* If using the %year% tag, add a link to the yearly archive. */
410
+ if ( '%year%' == $tag )
411
+ $trail[] = '<a href="' . get_year_link( get_the_time( 'Y', $post_id ) ) . '" title="' . get_the_time( esc_attr__( 'Y', $textdomain ), $post_id ) . '">' . get_the_time( __( 'Y', $textdomain ), $post_id ) . '</a>';
412
+
413
+ /* If using the %monthnum% tag, add a link to the monthly archive. */
414
+ elseif ( '%monthnum%' == $tag )
415
+ $trail[] = '<a href="' . get_month_link( get_the_time( 'Y', $post_id ), get_the_time( 'm', $post_id ) ) . '" title="' . get_the_time( esc_attr__( 'F Y', $textdomain ), $post_id ) . '">' . get_the_time( __( 'F', $textdomain ), $post_id ) . '</a>';
416
+
417
+ /* If using the %day% tag, add a link to the daily archive. */
418
+ elseif ( '%day%' == $tag )
419
+ $trail[] = '<a href="' . get_day_link( get_the_time( 'Y', $post_id ), get_the_time( 'm', $post_id ), get_the_time( 'd', $post_id ) ) . '" title="' . get_the_time( esc_attr__( 'F j, Y', $textdomain ), $post_id ) . '">' . get_the_time( __( 'd', $textdomain ), $post_id ) . '</a>';
420
+
421
+ /* If using the %author% tag, add a link to the post author archive. */
422
+ elseif ( '%author%' == $tag )
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 );
430
+
431
+ /* Check that categories were returned. */
432
+ if ( $terms ) {
433
+
434
+ /* Sort the terms by ID and get the first category. */
435
+ usort( $terms, '_usort_terms_by_ID' );
436
+ $term = get_term( $terms[0], 'category' );
437
+
438
+ /* If the category has a parent, add the hierarchy to the trail. */
439
+ if ( 0 !== $term->parent )
440
+ $trail = array_merge( $trail, breadcrumb_trail_get_term_parents( $term->parent, 'category' ) );
441
+
442
+ /* Add the category archive link to the trail. */
443
+ $trail[] = '<a href="' . get_term_link( $term, 'category' ) . '" title="' . esc_attr( $term->name ) . '">' . $term->name . '</a>';
444
+ }
445
+ }
446
+ }
447
+ }
448
+
449
+ /* Return the $trail array. */
450
+ return $trail;
451
  }
452
 
453
  /**
455
  * a clear path back to home given what would normally be a "ghost" directory. If any page matches the given
456
  * path, it'll be added. But, it's also just a way to check for a hierarchy with hierarchical post types.
457
  *
458
+ * @since 0.3.0
459
  * @param int $post_id ID of the post whose parents we want.
460
  * @param string $path Path of a potential parent page.
461
  * @return array $trail Array of parent page links.
538
  * Searches for term parents of hierarchical taxonomies. This function is similar to the WordPress
539
  * function get_category_parents() but handles any type of taxonomy.
540
  *
541
+ * @since 0.3.0
542
  * @param int $parent_id The ID of the first parent.
543
  * @param object|string $taxonomy The taxonomy of the term whose parents we want.
544
  * @return array $trail Array of links to parent terms.
574
  return $trail;
575
  }
576
 
577
+ /**
578
+ * Returns the textdomain used by the script and allows it to be filtered by plugins/themes.
579
+ *
580
+ * @since 0.4.0
581
+ * @returns string The textdomain for the script.
582
+ */
583
+ function breadcrumb_trail_textdomain() {
584
+ return apply_filters( 'breadcrumb_trail_textdomain', 'breadcrumb-trail' );
585
+ }
586
+
587
  ?>
readme.html CHANGED
@@ -111,13 +111,15 @@ Basically, this just checks to see if the plugin is activated and has loaded the
111
 
112
  <p>If you're a theme developer, you can always add checks for this plugin and place it yourself within your template files or use <code>add_action()</code> to add it to a custom theme hook.</p>
113
 
114
- <p>This plugin has two filter hooks for use as well:</p>
115
 
116
  <dl>
117
  <dt>breadcrumb_trail_args</dt>
118
  <dd>Overwrite the arguments input and/or the defaults.</dd>
119
  <dt>breadcrumb_trail</dt>
120
  <dd>Completely overwrite the entire breadcrumb menu.</dd>
 
 
121
  </dl>
122
 
123
  <h2>Plugin support</h2>
@@ -132,7 +134,7 @@ Basically, this just checks to see if the plugin is activated and has loaded the
132
 
133
  <p>This plugin is copyrighted to <a href="http://justintadlock.com" title="Justin Tadlock">Justin Tadlock</a>.</p>
134
 
135
- <p>2008&thinsp;&ndash;&thinsp;2010 &copy; Justin Tadlock. All rights reserved.</p>
136
 
137
  </body>
138
  </html>
111
 
112
  <p>If you're a theme developer, you can always add checks for this plugin and place it yourself within your template files or use <code>add_action()</code> to add it to a custom theme hook.</p>
113
 
114
+ <p>This plugin has three filter hooks for use as well:</p>
115
 
116
  <dl>
117
  <dt>breadcrumb_trail_args</dt>
118
  <dd>Overwrite the arguments input and/or the defaults.</dd>
119
  <dt>breadcrumb_trail</dt>
120
  <dd>Completely overwrite the entire breadcrumb menu.</dd>
121
+ <dt>breadcrumb_trail_items</dt>
122
+ <dd>Overwrite or extend the rrray of items shown in the trail.</dd>
123
  </dl>
124
 
125
  <h2>Plugin support</h2>
134
 
135
  <p>This plugin is copyrighted to <a href="http://justintadlock.com" title="Justin Tadlock">Justin Tadlock</a>.</p>
136
 
137
+ <p>2008&thinsp;&ndash;&thinsp;2011 &copy; Justin Tadlock. All rights reserved.</p>
138
 
139
  </body>
140
  </html>
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  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.0
6
- Tested up to: 3.0.1
7
- Stable tag: 0.3.2
8
 
9
  An easy-to-use template tag for showing a breadcrumb menu on your site.
10
 
@@ -56,6 +56,14 @@ There are no screenshots for this plugin.
56
 
57
  == Changelog ==
58
 
 
 
 
 
 
 
 
 
59
  **Version 0.3.1**
60
 
61
  * Smarter logic in certain areas.
2
  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
 
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.
62
+ * New filter hook: `breadcrumb_trail_items`, which allows devs to filter just the items.
63
+ * New function: `breadcrumb_trail_map_rewrite_tags()`, which maps the permalink structure tags set under Permalink Settings in the admin to make for a much more accurate breadcrumb trail.
64
+ * New function: `breadcrumb_trail_textdomain()`, which can be filtered when integrating the plugin into a theme to match the theme's textdomain.
65
+ * Added functionality to handle WP 3.1 post type enhancements.
66
+
67
  **Version 0.3.1**
68
 
69
  * Smarter logic in certain areas.