Breadcrumb Trail - Version 0.6.0

Version Description

Version 0.6.0+

If upgrading to a version earlier than 0.6.0 to 0.6.0+, you should check the readme.md documentation on some of the argument changes if you've been padding custom arguments into the breadcrumb_trail() function.

Download this release

Release Info

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

Code changes from version 0.4.1 to 0.6.0

breadcrumb-trail-en_EN.mo DELETED
Binary file
breadcrumb-trail-en_EN.po DELETED
@@ -1,87 +0,0 @@
1
- msgid ""
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"
9
- "MIME-Version: 1.0\n"
10
- "Content-Type: text/plain; charset=UTF-8\n"
11
- "Content-Transfer-Encoding: 8bit\n"
12
- "X-Poedit-Language: English\n"
13
- "X-Poedit-Country: UNITED STATES\n"
14
- "X-Poedit-KeywordsList: _e;__;esc_attr_e;esc_attr__;esc_html_e;esc_html__\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
@@ -1,589 +1,16 @@
1
<?php
2
/**
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
- *
10
- * Breadcrumb Trail - A breadcrumb menu script for WordPress.
11
- *
12
- * Breadcrumb Trail is a script for showing a breadcrumb trail for any type of page. It tries to anticipate
13
- * any type of structure and display the best possible trail that matches your site's permalink structure.
14
- * While not perfect, it attempts to fill in the gaps left by many other breadcrumb scripts.
15
- *
16
- * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
17
- * General Public License version 2, as published by the Free Software Foundation. You may NOT assume
18
- * that you can use any other version of the GPL.
19
- *
20
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
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
*/
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
-
52
- /* Get the textdomain. */
53
- $textdomain = breadcrumb_trail_textdomain();
54
-
55
- /* Create an empty variable for the breadcrumb. */
56
- $breadcrumb = '';
57
-
58
- /* Set up the default arguments for the breadcrumb. */
59
- $defaults = array(
60
- 'separator' => '/',
61
- 'before' => '<span class="breadcrumb-title">' . __( 'Browse:', $textdomain ) . '</span>',
62
- 'after' => false,
63
- 'front_page' => true,
64
- 'show_home' => __( 'Home', $textdomain ),
65
- 'echo' => true
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 );
76
-
77
- /* Parse the arguments and extract them for easy variable naming. */
78
- $args = wp_parse_args( $args, $defaults );
79
-
80
- /* Get the trail items. */
81
- $trail = breadcrumb_trail_get_items( $args );
82
-
83
- /* Connect the breadcrumb trail if there are items in the trail. */
84
- if ( !empty( $trail ) && is_array( $trail ) ) {
85
-
86
- /* Open the breadcrumb trail containers. */
87
- $breadcrumb = '<div class="breadcrumb breadcrumbs"><div class="breadcrumb-trail">';
88
-
89
- /* If $before was set, wrap it in a container. */
90
- $breadcrumb .= ( !empty( $args['before'] ) ? '<span class="trail-before">' . $args['before'] . '</span> ' : '' );
91
-
92
- /* Wrap the $trail['trail_end'] value in a container. */
93
- if ( !empty( $trail['trail_end'] ) )
94
- $trail['trail_end'] = '<span class="trail-end">' . $trail['trail_end'] . '</span>';
95
-
96
- /* Format the separator. */
97
- $separator = ( !empty( $args['separator'] ) ? '<span class="sep">' . $args['separator'] . '</span>' : '<span class="sep">/</span>' );
98
-
99
- /* Join the individual trail items into a single string. */
100
- $breadcrumb .= join( " {$separator} ", $trail );
101
-
102
- /* If $after was set, wrap it in a container. */
103
- $breadcrumb .= ( !empty( $args['after'] ) ? ' <span class="trail-after">' . $args['after'] . '</span>' : '' );
104
-
105
- /* Close the breadcrumb trail containers. */
106
- $breadcrumb .= '</div></div>';
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'] )
114
- echo $breadcrumb;
115
- else
116
- return $breadcrumb;
117
- }
118
-
119
- /**
120
- * Gets the items for the breadcrumb trail. This is the heart of the script. It checks the current page
121
- * being viewed and decided based on the information provided by WordPress what items should be
122
- * added to the breadcrumb trail.
123
- *
124
- * @since 0.4.0
125
- * @todo Build in caching based on the queried object ID.
126
- * @param array $args Mixed arguments for the menu.
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();
134
-
135
- /* Set up an empty trail array and empty path. */
136
- $trail = array();
137
- $path = '';
138
-
139
- /* If $show_home is set and we're not on the front page of the site, link to the home page. */
140
- if ( !is_front_page() && $args['show_home'] )
141
- $trail[] = '<a href="' . home_url() . '" title="' . esc_attr( get_bloginfo( 'name' ) ) . '" rel="home" class="trail-begin">' . $args['show_home'] . '</a>';
142
-
143
- /* If viewing the front page of the site. */
144
- if ( is_front_page() ) {
145
- if ( $args['show_home'] && $args['front_page'] )
146
- $trail['trail_end'] = "{$args['show_home']}";
147
- }
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
- }
155
-
156
- /* If viewing a singular post (page, attachment, etc.). */
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
-
165
- /* Get the post type object. */
166
- $post_type_object = get_post_type_object( $post_type );
167
-
168
- /* If viewing a singular 'post'. */
169
- if ( 'post' == $post_type ) {
170
-
171
- /* If $front has been set, add it to the $path. */
172
- $path .= trailingslashit( $wp_rewrite->front );
173
-
174
- /* If there's a path, check for parents. */
175
- if ( !empty( $path ) )
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'. */
183
- elseif ( 'attachment' == $post_type ) {
184
-
185
- /* If $front has been set, add it to the $path. */
186
- $path .= trailingslashit( $wp_rewrite->front );
187
-
188
- /* If there's a path, check for parents. */
189
- if ( !empty( $path ) )
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. */
197
- elseif ( 'page' !== $post_type ) {
198
-
199
- /* If $front has been set, add it to the $path. */
200
- if ( $post_type_object->rewrite['with_front'] && $wp_rewrite->front )
201
- $path .= trailingslashit( $wp_rewrite->front );
202
-
203
- /* If there's a slug, add it to the $path. */
204
- if ( !empty( $post_type_object->rewrite['slug'] ) )
205
- $path .= $post_type_object->rewrite['slug'];
206
-
207
- /* If there's a path, check for parents. */
208
- if ( !empty( $path ) )
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
-
216
- /* If the post type path returns nothing and there is a parent, get its parents. */
217
- if ( ( empty( $path ) && 0 !== $parent ) || ( 'attachment' == $post_type ) )
218
- $trail = array_merge( $trail, breadcrumb_trail_get_parents( $parent, '' ) );
219
-
220
- /* Or, if the post type is hierarchical and there's a parent, get its parents. */
221
- elseif ( 0 !== $parent && is_post_type_hierarchical( $post_type ) )
222
- $trail = array_merge( $trail, breadcrumb_trail_get_parents( $parent, '' ) );
223
-
224
- /* Display terms for specific post type taxonomy if requested. */
225
- if ( !empty( $args["singular_{$post_type}_taxonomy"] ) && $terms = get_the_term_list( $post_id, $args["singular_{$post_type}_taxonomy"], '', ', ', '' ) )
226
- $trail[] = $terms;
227
-
228
- /* End with the post title. */
229
- $post_title = get_the_title();
230
- if ( !empty( $post_title ) )
231
- $trail['trail_end'] = $post_title;
232
- }
233
-
234
- /* If we're viewing any type of archive. */
235
- elseif ( is_archive() ) {
236
-
237
- /* If viewing a taxonomy term archive. */
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. */
245
- if ( is_category() )
246
- $path = get_option( 'category_base' );
247
- elseif ( is_tag() )
248
- $path = get_option( 'tag_base' );
249
- else {
250
- if ( $taxonomy->rewrite['with_front'] && $wp_rewrite->front )
251
- $path = trailingslashit( $wp_rewrite->front );
252
- $path .= $taxonomy->rewrite['slug'];
253
- }
254
-
255
- /* Get parent pages by path if they exist. */
256
- if ( $path )
257
- $trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) );
258
-
259
- /* If the taxonomy is hierarchical, list its parent terms. */
260
- if ( is_taxonomy_hierarchical( $term->taxonomy ) && $term->parent )
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' ) );
272
-
273
- /* If $front has been set, add it to the $path. */
274
- if ( $post_type_object->rewrite['with_front'] && $wp_rewrite->front )
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 ) )
283
- $trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) );
284
-
285
- /* Add the post type [plural] name to the trail end. */
286
- $trail['trail_end'] = $post_type_object->labels->name;
287
- }
288
-
289
- /* If viewing an author archive. */
290
- elseif ( is_author() ) {
291
-
292
- /* If $front has been set, add it to $path. */
293
- if ( !empty( $wp_rewrite->front ) )
294
- $path .= trailingslashit( $wp_rewrite->front );
295
-
296
- /* If an $author_base exists, add it to $path. */
297
- if ( !empty( $wp_rewrite->author_base ) )
298
- $path .= $wp_rewrite->author_base;
299
-
300
- /* If $path exists, check for parent pages. */
301
- if ( !empty( $path ) )
302
- $trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) );
303
-
304
- /* Add the author's display name to the trail end. */
305
- $trail['trail_end'] = get_the_author_meta( 'display_name', get_query_var( 'author' ) );
306
- }
307
-
308
- /* If viewing a time-based archive. */
309
- elseif ( is_time() ) {
310
-
311
- if ( get_query_var( 'minute' ) && get_query_var( 'hour' ) )
312
- $trail['trail_end'] = get_the_time( __( 'g:i a', $textdomain ) );
313
-
314
- elseif ( get_query_var( 'minute' ) )
315
- $trail['trail_end'] = sprintf( __( 'Minute %1$s', $textdomain ), get_the_time( __( 'i', $textdomain ) ) );
316
-
317
- elseif ( get_query_var( 'hour' ) )
318
- $trail['trail_end'] = get_the_time( __( 'g a', $textdomain ) );
319
- }
320
-
321
- /* If viewing a date-based archive. */
322
- elseif ( is_date() ) {
323
-
324
- /* If $front has been set, check for parent pages. */
325
- if ( $wp_rewrite->front )
326
- $trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $wp_rewrite->front ) );
327
-
328
- if ( is_day() ) {
329
- $trail[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . get_the_time( esc_attr__( 'Y', $textdomain ) ) . '">' . get_the_time( __( 'Y', $textdomain ) ) . '</a>';
330
- $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>';
331
- $trail['trail_end'] = get_the_time( __( 'd', $textdomain ) );
332
- }
333
-
334
- elseif ( get_query_var( 'w' ) ) {
335
- $trail[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . get_the_time( esc_attr__( 'Y', $textdomain ) ) . '">' . get_the_time( __( 'Y', $textdomain ) ) . '</a>';
336
- $trail['trail_end'] = sprintf( __( 'Week %1$s', $textdomain ), get_the_time( esc_attr__( 'W', $textdomain ) ) );
337
- }
338
-
339
- elseif ( is_month() ) {
340
- $trail[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . get_the_time( esc_attr__( 'Y', $textdomain ) ) . '">' . get_the_time( __( 'Y', $textdomain ) ) . '</a>';
341
- $trail['trail_end'] = get_the_time( __( 'F', $textdomain ) );
342
- }
343
-
344
- elseif ( is_year() ) {
345
- $trail['trail_end'] = get_the_time( __( 'Y', $textdomain ) );
346
- }
347
- }
348
- }
349
-
350
- /* If viewing search results. */
351
- elseif ( is_search() )
352
- $trail['trail_end'] = sprintf( __( 'Search results for &quot;%1$s&quot;', $textdomain ), esc_attr( get_search_query() ) );
353
-
354
- /* If viewing a 404 error page. */
355
- elseif ( is_404() )
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
- /**
363
- * Turns %tag% from permalink structures into usable links for the breadcrumb trail. This feels kind of
364
- * hackish for now because we're checking for specific %tag% examples and only doing it for the 'post'
365
- * post type. In the future, maybe it'll handle a wider variety of possibilities, especially for custom post
366
- * types.
367
- *
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();
378
-
379
- /* Make sure there's a $path and $post_id before continuing. */
380
- if ( empty( $path ) || empty( $post_id ) )
381
- return $trail;
382
-
383
- /* Get the post based on the post ID. */
384
- $post = get_post( $post_id );
385
-
386
- /* If no post is returned, an error is returned, or the post does not have a 'post' post type, return. */
387
- if ( empty( $post ) || is_wp_error( $post ) || 'post' !== $post->post_type )
388
- return $trail;
389
-
390
- /* Get the textdomain. */
391
- $textdomain = breadcrumb_trail_textdomain();
392
-
393
- /* Trim '/' from both sides of the $path. */
394
- $path = trim( $path, '/' );
395
-
396
- /* Split the $path into an array of strings. */
397
- $matches = explode( '/', $path );
398
-
399
- /* If matches are found for the path. */
400
- if ( is_array( $matches ) ) {
401
-
402
- /* Loop through each of the matches, adding each to the $trail array. */
403
- foreach ( $matches as $match ) {
404
-
405
- /* Trim any '/' from the $match. */
406
- $tag = trim( $match, '/' );
407
-
408
- /* If using the %year% tag, add a link to the yearly archive. */
409
- if ( '%year%' == $tag )
410
- $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>';
411
-
412
- /* If using the %monthnum% tag, add a link to the monthly archive. */
413
- elseif ( '%monthnum%' == $tag )
414
- $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>';
415
-
416
- /* If using the %day% tag, add a link to the daily archive. */
417
- elseif ( '%day%' == $tag )
418
- $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>';
419
-
420
- /* If using the %author% tag, add a link to the post author archive. */
421
- elseif ( '%author%' == $tag )
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 );
429
-
430
- /* Check that categories were returned. */
431
- if ( $terms ) {
432
-
433
- /* Sort the terms by ID and get the first category. */
434
- usort( $terms, '_usort_terms_by_ID' );
435
- $term = get_term( $terms[0], 'category' );
436
-
437
- /* If the category has a parent, add the hierarchy to the trail. */
438
- if ( 0 !== $term->parent )
439
- $trail = array_merge( $trail, breadcrumb_trail_get_term_parents( $term->parent, 'category' ) );
440
-
441
- /* Add the category archive link to the trail. */
442
- $trail[] = '<a href="' . get_term_link( $term, 'category' ) . '" title="' . esc_attr( $term->name ) . '">' . $term->name . '</a>';
443
- }
444
- }
445
- }
446
- }
447
-
448
- /* Return the $trail array. */
449
- return $trail;
450
- }
451
-
452
- /**
453
- * Gets parent pages of any post type or taxonomy by the ID or Path. The goal of this function is to create
454
- * a clear path back to home given what would normally be a "ghost" directory. If any page matches the given
455
- * path, it'll be added. But, it's also just a way to check for a hierarchy with hierarchical post types.
456
- *
457
- * @since 0.3.0
458
- * @param int $post_id ID of the post whose parents we want.
459
- * @param string $path Path of a potential parent page.
460
- * @return array $trail Array of parent page links.
461
- */
462
- function breadcrumb_trail_get_parents( $post_id = '', $path = '' ) {
463
-
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;
473
-
474
- /* If the post ID is empty, use the path to get the ID. */
475
- if ( empty( $post_id ) ) {
476
-
477
- /* Get parent post by the path. */
478
- $parent_page = get_page_by_path( $path );
479
-
480
- /* If a parent post is found, set the $post_id variable to it. */
481
- if ( !empty( $parent_page ) )
482
- $post_id = $parent_page->ID;
483
- }
484
-
485
- /* If a post ID and path is set, search for a post by the given path. */
486
- if ( $post_id == 0 && !empty( $path ) ) {
487
-
488
- /* Separate post names into separate paths by '/'. */
489
- $path = trim( $path, '/' );
490
- preg_match_all( "/\/.*?\z/", $path, $matches );
491
-
492
- /* If matches are found for the path. */
493
- if ( isset( $matches ) ) {
494
-
495
- /* Reverse the array of matches to search for posts in the proper order. */
496
- $matches = array_reverse( $matches );
497
-
498
- /* Loop through each of the path matches. */
499
- foreach ( $matches as $match ) {
500
-
501
- /* If a match is found. */
502
- if ( isset( $match[0] ) ) {
503
-
504
- /* Get the parent post by the given path. */
505
- $path = str_replace( $match[0], '', $path );
506
- $parent_page = get_page_by_path( trim( $path, '/' ) );
507
-
508
- /* If a parent post is found, set the $post_id and break out of the loop. */
509
- if ( !empty( $parent_page ) && $parent_page->ID > 0 ) {
510
- $post_id = $parent_page->ID;
511
- break;
512
- }
513
- }
514
- }
515
- }
516
- }
517
-
518
- /* While there's a post ID, add the post link to the $parents array. */
519
- while ( $post_id ) {
520
-
521
- /* Get the post by ID. */
522
- $page = get_page( $post_id );
523
-
524
- /* Add the formatted post link to the array of parents. */
525
- $parents[] = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . get_the_title( $post_id ) . '</a>';
526
-
527
- /* Set the parent post's parent to the post ID. */
528
- $post_id = $page->post_parent;
529
- }
530
-
531
- /* If we have parent posts, reverse the array to put them in the proper order for the trail. */
532
- if ( isset( $parents ) )
533
- $trail = array_reverse( $parents );
534
-
535
- /* Return the trail of parent posts. */
536
- return $trail;
537
- }
538
-
539
- /**
540
- * Searches for term parents of hierarchical taxonomies. This function is similar to the WordPress
541
- * function get_category_parents() but handles any type of taxonomy.
542
- *
543
- * @since 0.3.0
544
- * @param int $parent_id The ID of the first parent.
545
- * @param object|string $taxonomy The taxonomy of the term whose parents we want.
546
- * @return array $trail Array of links to parent terms.
547
- */
548
- function breadcrumb_trail_get_term_parents( $parent_id = '', $taxonomy = '' ) {
549
-
550
- /* Set up some default arrays. */
551
- $trail = array();
552
- $parents = array();
553
-
554
- /* If no term parent ID or taxonomy is given, return an empty array. */
555
- if ( empty( $parent_id ) || empty( $taxonomy ) )
556
- return $trail;
557
-
558
- /* While there is a parent ID, add the parent term link to the $parents array. */
559
- while ( $parent_id ) {
560
-
561
- /* Get the parent term. */
562
- $parent = get_term( $parent_id, $taxonomy );
563
-
564
- /* Add the formatted term link to the array of parent terms. */
565
- $parents[] = '<a href="' . get_term_link( $parent, $taxonomy ) . '" title="' . esc_attr( $parent->name ) . '">' . $parent->name . '</a>';
566
-
567
- /* Set the parent term's parent as the parent ID. */
568
- $parent_id = $parent->parent;
569
- }
570
-
571
- /* If we have parent terms, reverse the array to put them in the proper order for the trail. */
572
- if ( !empty( $parents ) )
573
- $trail = array_reverse( $parents );
574
-
575
- /* Return the trail of parent terms. */
576
- return $trail;
577
- }
578
-
579
- /**
580
- * Returns the textdomain used by the script and allows it to be filtered by plugins/themes.
581
- *
582
- * @since 0.4.0
583
- * @returns string The textdomain for the script.
584
- */
585
- function breadcrumb_trail_textdomain() {
586
- return apply_filters( 'breadcrumb_trail_textdomain', 'breadcrumb-trail' );
587
- }
588
589
- ?>
1
<?php
2
/**
3
* Plugin Name: Breadcrumb Trail
4
+ * Plugin URI: http://themehybrid.com/plugins/breadcrumb-trail
5
+ * Description: A smart breadcrumb menu plugin embedded with <a href="http://schema.org">Schema.org</a> microdata that can handle variations in site structure more accurately than any other breadcrumb plugin for WordPress. Insert into your theme with the <code>breadcrumb_trail()</code> template tag.
6
+ * Version: 0.6.0
7
* Author: Justin Tadlock
8
* Author URI: http://justintadlock.com
9
*/
10
11
+ /* Extra check in case the script is being loaded by a theme. */
12
+ if ( !function_exists( 'breadcrumb_trail' ) )
13
+ require_once( 'inc/breadcrumbs.php' );
14
15
+ /* Load translation files. Note: Remove this line if packaging with a theme. */
16
+ load_plugin_textdomain( 'breadcrumb-trail', false, 'breadcrumb-trail/languages' );
breadcrumb-trail.pot DELETED
@@ -1,76 +0,0 @@
1
- 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"
9
- "MIME-Version: 1.0\n"
10
- "Content-Type: text/plain; charset=UTF-8\n"
11
- "Content-Transfer-Encoding: 8bit\n"
12
- "X-Poedit-Language: English\n"
13
- "X-Poedit-Country: UNITED STATES\n"
14
- "X-Poedit-KeywordsList: _e;__;esc_attr_e;esc_attr__;esc_html_e;esc_html__\n"
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
-
inc/breadcrumbs.php ADDED
@@ -0,0 +1,1217 @@
1
+ <?php
2
+ /**
3
+ * Breadcrumb Trail - A breadcrumb menu script for WordPress.
4
+ *
5
+ * Breadcrumb Trail is a script for showing a breadcrumb trail for any type of page. It tries to
6
+ * anticipate any type of structure and display the best possible trail that matches your site's
7
+ * permalink structure. While not perfect, it attempts to fill in the gaps left by many other
8
+ * breadcrumb scripts.
9
+ *
10
+ * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
11
+ * General Public License as published by the Free Software Foundation; either version 2 of the License,
12
+ * or (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
15
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *
17
+ * @package BreadcrumbTrail
18
+ * @version 0.6.0
19
+ * @author Justin Tadlock <justin@justintadlock.com>
20
+ * @copyright Copyright (c) 2008 - 2013, Justin Tadlock
21
+ * @link http://themehybrid.com/plugins/breadcrumb-trail
22
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23
+ */
24
+
25
+ /**
26
+ * Shows a breadcrumb for all types of pages. This is a wrapper function for the Breadcrumb_Trail class,
27
+ * which should be used in theme templates.
28
+ *
29
+ * @since 0.1.0
30
+ * @access public
31
+ * @param array $args Arguments to pass to Breadcrumb_Trail.
32
+ * @return void
33
+ */
34
+ function breadcrumb_trail( $args = array() ) {
35
+
36
+ if ( function_exists( 'is_bbpress' ) && is_bbpress() )
37
+ $breadcrumb = new bbPress_Breadcrumb_Trail( $args );
38
+ else
39
+ $breadcrumb = new Breadcrumb_Trail( $args );
40
+
41
+ $breadcrumb->trail();
42
+ }
43
+
44
+ /**
45
+ * Creates a breadcrumbs menu for the site based on the current page that's being viewed by the user.
46
+ *
47
+ * @since 0.6.0
48
+ */
49
+ class Breadcrumb_Trail {
50
+
51
+ /**
52
+ * Array of items belonging to the current breadcrumb trail.
53
+ *
54
+ * @since 0.1.0
55
+ * @access public
56
+ * @var array
57
+ */
58
+ public $items = array();
59
+
60
+ /**
61
+ * Arguments used to build the breadcrumb trail.
62
+ *
63
+ * @since 0.1.0
64
+ * @access public
65
+ * @var array
66
+ */
67
+ public $args = array();
68
+
69
+ /**
70
+ * Sets up the breadcrumb trail.
71
+ *
72
+ * @since 0.6.0
73
+ * @access public
74
+ * @param array $args The arguments for how to build the breadcrumb trail.
75
+ * @return void
76
+ */
77
+ public function __construct( $args = array() ) {
78
+
79
+ /* Remove the bbPress breadcrumbs. */
80
+ add_filter( 'bbp_get_breadcrumb', '__return_false' );
81
+
82
+ $defaults = array(
83
+ 'container' => 'div',
84
+ 'separator' => '&#47;',
85
+ 'before' => '',
86
+ 'after' => '',
87
+ 'show_on_front' => true,
88
+ 'network' => false,
89
+ //'show_edit_link' => false,
90
+ 'show_title' => true,
91
+ 'show_browse' => true,
92
+ 'echo' => true,
93
+
94
+ /* Post taxonomy (examples follow). */
95
+ 'post_taxonomy' => array(
96
+ // 'post' => 'post_tag',
97
+ // 'book' => 'genre',
98
+ ),
99
+
100
+ /* Labels for text used (see Breadcrumb_Trail::default_labels). */
101
+ 'labels' => array()
102
+ );
103
+
104
+ $this->args = apply_filters( 'breadcrumb_trail_args', wp_parse_args( $args, $defaults ) );
105
+
106
+ /* Merge the user-added labels with the defaults. */
107
+ $this->args['labels'] = wp_parse_args( $this->args['labels'], $this->default_labels() );
108
+
109
+ $this->do_trail_items();
110
+ }
111
+
112
+ /**
113
+ * Formats and outputs the breadcrumb trail.
114
+ *
115
+ * @since 0.6.0
116
+ * @access public
117
+ * @return string
118
+ */
119
+ public function trail() {
120
+
121
+ $breadcrumb = '';
122
+
123
+ /* Connect the breadcrumb trail if there are items in the trail. */
124
+ if ( !empty( $this->items ) && is_array( $this->items ) ) {
125
+
126
+ /* Open the breadcrumb trail containers. */
127
+ $breadcrumb = "\n\t\t" . '<' . tag_escape( $this->args['container'] ) . ' class="breadcrumb-trail breadcrumbs" itemprop="breadcrumb">';
128
+
129
+ /* If $before was set, wrap it in a container. */
130
+ $breadcrumb .= ( !empty( $this->args['before'] ) ? "\n\t\t\t" . '<span class="trail-before">' . $this->args['before'] . '</span> ' . "\n\t\t\t" : '' );
131
+
132
+ /* Add 'browse' label if it should be shown. */
133
+ if ( true === $this->args['show_browse'] )
134
+ $breadcrumb .= "\n\t\t\t" . '<span class="trail-browse">' . $this->args['labels']['browse'] . '</span> ';
135
+
136
+ /* Adds the 'trail-begin' class around first item if there's more than one item. */
137
+ if ( 1 < count( $this->items ) )
138
+ array_unshift( $this->items, '<span class="trail-begin">' . array_shift( $this->items ) . '</span>' );
139
+
140
+ /* Adds the 'trail-end' class around last item. */
141
+ array_push( $this->items, '<span class="trail-end">' . array_pop( $this->items ) . '</span>' );
142
+
143
+ /* Format the separator. */
144
+ $separator = ( !empty( $this->args['separator'] ) ? '<span class="sep">' . $this->args['separator'] . '</span>' : '<span class="sep">/</span>' );
145
+
146
+ /* Join the individual trail items into a single string. */
147
+ $breadcrumb .= join( "\n\t\t\t {$separator} ", $this->items );
148
+
149
+ /* If $after was set, wrap it in a container. */
150
+ $breadcrumb .= ( !empty( $this->args['after'] ) ? "\n\t\t\t" . ' <span class="trail-after">' . $this->args['after'] . '</span>' : '' );
151
+
152
+ /* Close the breadcrumb trail containers. */
153
+ $breadcrumb .= "\n\t\t" . '</' . tag_escape( $this->args['container'] ) . '>';
154
+ }
155
+
156
+ /* Allow developers to filter the breadcrumb trail HTML. */
157
+ $breadcrumb = apply_filters( 'breadcrumb_trail', $breadcrumb, $this->args );
158
+
159
+ if ( true === $this->args['echo'] )
160
+ echo $breadcrumb;
161
+ else
162
+ return $breadcrumb;
163
+ }
164
+
165
+ /**
166
+ * Returns an array of the default labels.
167
+ *
168
+ * @since 0.6.0
169
+ * @access public
170
+ * @return array
171
+ */
172
+ public function default_labels() {
173
+
174
+ $labels = array(
175
+ 'browse' => __( 'Browse:', 'breadcrumb-trail' ),
176
+ 'home' => __( 'Home', 'breadcrumb-trail' ),
177
+ 'search' => __( 'Search results for "%s"', 'breadcrumb-trail' ),
178
+ 'error_404' => __( '404 Not Found', 'breadcrumb-trail' ),
179
+ 'paged' => __( 'Page %d', 'breadcrumb-trail' ),
180
+ 'archives' => __( 'Archives', 'breadcrumb-trail' ),
181
+ 'archive_minute_hour' => __( 'g:i a', 'breadcrumb-trail' ),
182
+ 'archive_minute' => __( 'Minute %d', 'breadcrumb-trail' ),
183
+ 'archive_hour' => __( 'g a', 'breadcrumb-trail' ),
184
+ 'archive_day' => __( 'd', 'breadcrumb-trail' ),
185
+ 'archive_week' => __( 'Week %d', 'breadcrumb-trail' ),
186
+ 'archive_month' => __( 'F', 'breadcrumb-trail' ),
187
+ 'archive_year' => __( 'Y', 'breadcrumb-trail' ),
188
+ // 'edit' => __( 'Edit', 'breadcrumb-trail' ), // @todo Implement edit link
189
+ );
190
+
191
+ return $labels;
192
+ }
193
+
194
+ /**
195
+ * Runs through the various WordPress conditional tags to check the current page being viewed. Once
196
+ * a condition is met, a specific method is launched to add items to the $items array.
197
+ *
198
+ * @since 0.6.0
199
+ * @access public
200
+ * @return void
201
+ */
202
+ public function do_trail_items() {
203
+
204
+ /* If viewing the front page. */
205
+ if ( is_front_page() ) {
206
+ $this->do_front_page_items();
207
+ }
208
+
209
+ /* If not viewing the front page. */
210
+ else {
211
+
212
+ /* Add the network and site home links. */
213
+ $this->do_network_home_link();
214
+ $this->do_site_home_link();
215
+
216
+ /* If viewing the home/blog page. */
217
+ if ( is_home() ) {
218
+ $this->do_posts_page_items();
219
+ }
220
+
221
+ /* If viewing a single post. */
222
+ elseif ( is_singular() ) {
223
+ $this->do_singular_items();
224
+ }
225
+
226
+ /* If viewing an archive page. */
227
+ elseif ( is_archive() ) {
228
+
229
+ if ( is_post_type_archive() )
230
+ $this->do_post_type_archive_items();
231
+
232
+ elseif ( is_category() || is_tag() || is_tax() )
233
+ $this->do_term_archive_items();
234
+
235
+ elseif ( is_author() )
236
+ $this->do_user_archive_items();
237
+
238
+ elseif ( get_query_var( 'minute' ) && get_query_var( 'hour' ) )
239
+ $this->do_minute_hour_archive_items();
240
+
241
+ elseif ( get_query_var( 'minute' ) )
242
+ $this->do_minute_archive_items();
243
+
244
+ elseif ( get_query_var( 'hour' ) )
245
+ $this->do_hour_archive_items();
246
+
247
+ elseif ( is_day() )
248
+ $this->do_day_archive_items();
249
+
250
+ elseif ( get_query_var( 'w' ) )
251
+ $this->do_week_archive_items();
252
+
253
+ elseif ( is_month() )
254
+ $this->do_month_archive_items();
255
+
256
+ elseif ( is_year() )
257
+ $this->do_year_archive_items();
258
+
259
+ else
260
+ $this->do_default_archive_items();
261
+ }
262
+
263
+ /* If viewing a search results page. */
264
+ elseif ( is_search() ) {
265
+ $this->do_search_items();
266
+ }
267
+
268
+ /* If viewing the 404 page. */
269
+ elseif ( is_404() ) {
270
+ $this->do_404_items();
271
+ }
272
+ }
273
+
274
+ /* Add paged items if they exist. */
275
+ $this->do_paged_items();
276
+
277
+ /* Allow developers to overwrite the items for the breadcrumb trail. */
278
+ $this->items = apply_filters( 'breadcrumb_trail_items', $this->items, $this->args );
279
+ }
280
+
281
+ /**
282
+ * Gets front items based on $wp_rewrite->front.
283
+ *
284
+ * @since 0.6.0
285
+ * @access public
286
+ * @return void
287
+ */
288
+ public function do_rewrite_front_items() {
289
+ global $wp_rewrite;
290
+
291
+ if ( $wp_rewrite->front )
292
+ $this->do_path_parents( $wp_rewrite->front );
293
+ }
294
+
295
+ /**
296
+ * Adds the page/paged number to the items array.
297
+ *
298
+ * @since 0.6.0
299
+ * @access public
300
+ * @return void
301
+ */
302
+ public function do_paged_items() {
303
+
304
+ /* If viewing a paged singular post. */
305
+ if ( is_singular() && 1 < get_query_var( 'page' ) && true === $this->args['show_title'] )
306
+ $this->items[] = sprintf( $this->args['labels']['paged'], absint( get_query_var( 'page' ) ) );
307
+
308
+ /* If viewing a paged archive-type page. */
309
+ elseif ( is_paged() && true === $this->args['show_title'] )
310
+ $this->items[] = sprintf( $this->args['labels']['paged'], absint( get_query_var( 'paged' ) ) );
311
+
312
+ }
313
+
314
+ /**
315
+ * Adds the network (all sites) home page link to the items array.
316
+ *
317
+ * @since 0.6.0
318
+ * @access public
319
+ * @return void
320
+ */
321
+ public function do_network_home_link() {
322
+ if ( is_multisite() && !is_main_site() && true === $this->args['network'] )
323
+ $this->items[] = '<a href="' . network_home_url() . '" title="' . esc_attr( $this->args['labels']['home'] ) . '">' . $this->args['labels']['home'] . '</a>';
324
+ }
325
+
326
+ /**
327
+ * Adds the current site's home page link to the items array.
328
+ *
329
+ * @since 0.6.0
330
+ * @access public
331
+ * @return void
332
+ */
333
+ public function do_site_home_link() {
334
+ $label = ( is_multisite() && !is_main_site() && true === $this->args['network'] ) ? get_bloginfo( 'name' ) : $this->args['labels']['home'];
335
+ $this->items[] = '<a href="' . home_url() . '" title="' . esc_attr( get_bloginfo( 'name' ) ) . '">' . $label . '</a>';
336
+ }
337
+
338
+ /**
339
+ * Adds items for the front page to the items array.
340
+ *
341
+ * @since 0.6.0
342
+ * @access public
343
+ * @return void
344
+ */
345
+ public function do_front_page_items() {
346
+
347
+ /* Only show front items if the 'show_on_front' argument is set to 'true'. */
348
+ if ( true === $this->args['show_on_front'] ) {
349
+
350
+ /* If on a paged view, add the home link items. */
351
+ if ( is_paged() ) {
352
+ $this->do_network_home_link();
353
+ $this->do_site_home_link();
354
+ }
355
+
356
+ /* If on the main front page, add the network home link item and the home item. */
357
+ else {
358
+ $this->do_network_home_link();
359
+
360
+ if ( true === $this->args['show_title'] )
361
+ $this->items[] = ( is_multisite() && true === $this->args['network'] ) ? get_bloginfo( 'name' ) : $this->args['labels']['home'];
362
+ }
363
+ }
364
+ }
365
+
366
+ /**
367
+ * Adds items for the posts page (i.e., is_home()) to the items array.
368
+ *
369
+ * @since 0.6.0
370
+ * @access public
371
+ * @return void
372
+ */
373
+ public function do_posts_page_items() {
374
+
375
+ /* Get the post ID and post. */
376
+ $post_id = get_queried_object_id();
377
+ $post = get_page( $post_id );
378
+
379
+ /* If the post has parents, add them to the trail. */
380
+ if ( 0 < $post->post_parent )
381
+ $this->do_post_parents( $post->post_parent );
382
+
383
+ /* Get the page title. */
384
+ $title = get_the_title( $post_id );
385
+
386
+ /* Add the posts page item. */
387
+ if ( is_paged() )
388
+ $this->items[] = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( $title ) . '">' . $title . '</a>';
389
+
390
+ elseif ( $title && true === $this->args['show_title'] )
391
+ $this->items[] = $title;
392
+ }
393
+
394
+ /**
395
+ * Adds singular post items to the items array.
396
+ *
397
+ * @since 0.6.0
398
+ * @access public
399
+ * @return void
400
+ */
401
+ public function do_singular_items() {
402
+
403
+ /* Get the queried post. */
404
+ $post = get_queried_object();
405
+ $post_id = get_queried_object_id();
406
+
407
+ /* If the post has a parent, follow the parent trail. */
408
+ if ( 0 < $post->post_parent )
409
+ $this->do_post_parents( $post->post_parent );
410
+
411
+ /* If the post doesn't have a parent, get its hierarchy based off the post type. */
412
+ else
413
+ $this->do_post_hierarchy( $post_id );
414
+
415
+ /* Display terms for specific post type taxonomy if requested. */
416
+ $this->do_post_terms( $post_id );
417
+
418
+ /* End with the post title. */
419
+ if ( $post_title = single_post_title( '', false ) ) {
420
+
421
+ if ( 1 < get_query_var( 'page' ) )
422
+ $this->items[] = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( $post_title ) . '">' . $post_title . '</a>';
423
+
424
+ elseif ( true === $this->args['show_title'] )
425
+ $this->items[] = $post_title;
426
+ }
427
+ }
428
+
429
+ /**
430
+ * Adds a specific post's parents to the items array.
431
+ *
432
+ * @since 0.6.0
433
+ * @access public
434
+ * @param int $post_id The ID of the post to get the parents of.
435
+ * @return void
436
+ */
437
+ public function do_post_parents( $post_id ) {
438
+ $parents = array();
439
+
440
+ while ( $post_id ) {
441
+
442
+ /* Get the post by ID. */
443
+ $post = get_post( $post_id );
444
+
445
+ /* Add the formatted post link to the array of parents. */
446
+ $parents[] = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . get_the_title( $post_id ) . '</a>';
447
+
448
+ /* If there's no longer a post parent, brea out of the loop. */
449
+ if ( 0 >= $post->post_parent )
450
+ break;
451
+
452
+ /* Change the post ID to the parent post to continue looping. */
453
+ $post_id = $post->post_parent;
454
+ }
455
+
456
+ /* Get the post hierarchy based off the final parent post. */
457
+ $this->do_post_hierarchy( $post_id );
458
+
459
+ /* Merge the parent items into the items array. */
460
+ $this->items = array_merge( $this->items, array_reverse( $parents ) );
461
+ }
462
+
463
+ /**
464
+ * Adds a post's terms from a specific taxonomy to the items array.
465
+ *
466
+ * @since 0.6.0
467
+ * @access public
468
+ * @param int $post_id The ID of the post to get the terms for.
469
+ * @return void
470
+ */
471
+ public function do_post_terms( $post_id ) {
472
+
473
+ /* Get the post type. */
474
+ $post_type = get_post_type( $post_id );
475
+
476
+ /* Add the terms of the taxonomy for this post. */
477
+ if ( !empty( $this->args['post_taxonomy'][ $post_type ] ) )
478
+ $this->items[] = get_the_term_list( $post_id, $this->args['post_taxonomy'][ $post_type ], '', ', ', '' );
479
+ }
480
+
481
+ /**
482
+ * Adds a specific post's hierarchy to the items array. The hierarchy is determined by post type's
483
+ * rewrite arguments and whether it has an archive page.
484
+ *
485
+ * @since 0.6.0
486
+ * @access public
487
+ * @param int $post_id The ID of the post to get the hierarchy for.
488
+ * @return void
489
+ */
490
+ public function do_post_hierarchy( $post_id ) {
491
+
492
+ /* Get the post type. */
493
+ $post_type = get_post_type( $post_id );
494
+ $post_type_object = get_post_type_object( $post_type );
495
+
496
+ /* If this is the 'post' post type, get the rewrite front items and map the rewrite tags. */
497
+ if ( 'post' === $post_type ) {
498
+
499
+ /* Add $wp_rewrite->front to the trail. */
500
+ $this->do_rewrite_front_items();
501
+
502
+ /* Map the rewrite tags. */
503
+ $this->map_rewrite_tags( $post_id, get_option( 'permalink_structure' ) );
504
+ }
505
+
506
+ /* If the post type has rewrite rules. */
507
+ elseif ( false !== $post_type_object->rewrite ) {
508
+
509
+ /* If 'with_front' is true, add $wp_rewrite->front to the trail. */
510
+ if ( $post_type_object->rewrite['with_front'] )
511
+ $this->do_rewrite_front_items();
512
+
513
+ /* If there's a path, check for parents. */
514
+ if ( !empty( $post_type_object->rewrite['slug'] ) )
515
+ $this->do_path_parents( $post_type_object->rewrite['slug'] );
516
+ }
517
+
518
+ /* If there's an archive page, add it to the trail. */
519
+ if ( !empty( $post_type_object->has_archive ) ) {
520
+
521
+ /* Add support for a non-standard label of 'archive_title' (special use case). */
522
+ $label = !empty( $post_type_object->labels->archive_title ) ? $post_type_object->labels->archive_title : $post_type_object->labels->name;
523
+
524
+ $this->items[] = '<a href="' . get_post_type_archive_link( $post_type ) . '" title="' . esc_attr( $label ) . '">' . $label . '</a>';
525
+ }
526
+ }
527
+
528
+ /**
529
+ * Gets post types by slug. This is needed because the get_post_types() function doesn't exactly
530
+ * match the 'has_archive' argument when it's set as a string instead of a boolean.
531
+ *
532
+ * @since 0.6.0
533
+ * @access public
534
+ * @param int $slug The post type archive slug to search for.
535
+ * @return void
536
+ */
537
+ public function get_post_types_by_slug( $slug ) {
538
+
539
+ $return = array();
540
+
541
+ $post_types = get_post_types( array(), 'objects' );
542
+
543
+ foreach ( $post_types as $type ) {
544
+
545
+ if ( $slug === $type->has_archive || ( true === $type->has_archive && $slug === $type->rewrite['slug'] ) )
546
+ $return[] = $type;
547
+ }
548
+
549
+ return $return;
550
+ }
551
+
552
+ /**
553
+ * Adds the items to the trail items array for taxonomy term archives.
554
+ *
555
+ * @since 0.6.0
556
+ * @access public
557
+ * @global object $wp_rewrite
558
+ * @return void
559
+ */
560
+ public function do_term_archive_items() {
561
+ global $wp_rewrite;
562
+
563
+ /* Get some taxonomy and term variables. */
564
+ $term = get_queried_object();
565
+ $taxonomy = get_taxonomy( $term->taxonomy );
566
+
567
+ /* If there are rewrite rules for the taxonomy. */
568
+ if ( false !== $taxonomy->rewrite ) {
569
+
570
+ /* If 'with_front' is true, dd $wp_rewrite->front to the trail. */
571
+ if ( $taxonomy->rewrite['with_front'] && $wp_rewrite->front )
572
+ $this->do_rewrite_front_items();
573
+
574
+ /* Get parent pages by path if they exist. */
575
+ $this->do_path_parents( $taxonomy->rewrite['slug'] );
576
+
577
+ /* Add post type archive if its 'has_archive' matches the taxonomy rewrite 'slug'. */
578
+ if ( $taxonomy->rewrite['slug'] ) {
579
+
580
+ $slug = trim( $taxonomy->rewrite['slug'], '/' );
581
+
582
+ /**
583
+ * Deals with the situation if the slug has a '/' between multiple strings. For
584
+ * example, "movies/genres" where "movies" is the post type archive.
585
+ */
586
+ $matches = explode( '/', $slug );
587
+
588
+ /* If matches are found for the path. */
589
+ if ( isset( $matches ) ) {
590
+
591
+ /* Reverse the array of matches to search for posts in the proper order. */
592
+ $matches = array_reverse( $matches );
593
+
594
+ /* Loop through each of the path matches. */
595
+ foreach ( $matches as $match ) {
596
+
597
+ /* If a match is found. */
598
+ $slug = $match;
599
+
600
+ /* Get public post types that match the rewrite slug. */
601
+ $post_types = $this->get_post_types_by_slug( $match );
602
+
603
+ if ( !empty( $post_types ) ) {
604
+
605
+ $post_type_object = $post_types[0];
606
+
607
+ /* Add support for a non-standard label of 'archive_title' (special use case). */
608
+ $label = !empty( $post_type_object->labels->archive_title ) ? $post_type_object->labels->archive_title : $post_type_object->labels->name;
609
+
610
+ /* Add the post type archive link to the trail. */
611
+ $this->items[] = '<a href="' . get_post_type_archive_link( $post_type_object->name ) . '" title="' . esc_attr( $label ) . '">' . $label . '</a>';
612
+
613
+ /* Break out of the loop. */
614
+ break;
615
+ }
616
+ }
617
+ }
618
+ }
619
+ }
620
+
621
+ /* If the taxonomy is hierarchical, list its parent terms. */
622
+ if ( is_taxonomy_hierarchical( $term->taxonomy ) && $term->parent )
623
+ $this->do_term_parents( $term->parent, $term->taxonomy );
624
+
625
+ /* Add the term name to the trail end. */
626
+ if ( is_paged() )
627
+ $this->items[] = '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '" title="' . esc_attr( single_term_title( '', false ) ) . '">' . single_term_title( '', false ) . '</a>';
628
+
629
+ elseif ( true === $this->args['show_title'] )
630
+ $this->items[] = single_term_title( '', false );
631
+ }
632
+
633
+ /**
634
+ * Adds the items to the trail items array for post type archives.
635
+ *
636
+ * @since 0.6.0
637
+ * @access public
638
+ * @return void
639
+ */
640
+ public function do_post_type_archive_items() {
641
+
642
+ /* Get the post type object. */
643
+ $post_type_object = get_post_type_object( get_query_var( 'post_type' ) );
644
+
645
+ if ( false !== $post_type_object->rewrite ) {
646
+
647
+ /* If 'with_front' is true, add $wp_rewrite->front to the trail. */
648
+ if ( $post_type_object->rewrite['with_front'] )
649
+ $this->do_rewrite_front_items();
650
+
651
+ /* If there's a rewrite slug, check for parents. */
652
+ if ( !empty( $post_type_object->rewrite['slug'] ) )
653
+ $this->do_path_parents( $post_type_object->rewrite['slug'] );
654
+ }
655
+
656
+ /* Add the post type [plural] name to the trail end. */
657
+ if ( is_paged() )
658
+ $this->items[] = '<a href="' . esc_url( get_post_type_archive_link( $post_type_object->name ) ) . '" title="' . esc_attr( post_type_archive_title( '', false ) ) . '">' . post_type_archive_title( '', false ) . '</a>';
659
+
660
+ elseif ( true === $this->args['show_title'] )
661
+ $this->items[] = post_type_archive_title( '', false );
662
+ }
663
+
664
+ /**
665
+ * Adds the items to the trail items array for user (author) archives.
666
+ *
667
+ * @since 0.6.0
668
+ * @access public
669
+ * @global object $wp_rewrite
670
+ * @return void
671
+ */
672
+ public function do_user_archive_items() {
673
+ global $wp_rewrite;
674
+
675
+ /* Add $wp_rewrite->front to the trail. */
676
+ $this->do_rewrite_front_items();
677
+
678
+ /* Get the user ID. */
679
+ $user_id = get_query_var( 'author' );
680
+
681
+ /* If $author_base exists, check for parent pages. */
682
+ if ( !empty( $wp_rewrite->author_base ) )
683
+ $this->do_path_parents( $wp_rewrite->author_base );
684
+
685
+ /* Add the author's display name to the trail end. */
686
+ if ( is_paged() )
687
+ $this->items[] = '<a href="'. esc_url( get_author_posts_url( $user_id ) ) . '" title="' . esc_attr( get_the_author_meta( 'display_name', $user_id ) ) . '">' . get_the_author_meta( 'display_name', $user_id ) . '</a>';
688
+
689
+ elseif ( true === $this->args['show_title'] )
690
+ $this->items[] = get_the_author_meta( 'display_name', $user_id );
691
+ }
692
+
693
+ /**
694
+ * Adds the items to the trail items array for minute + hour archives.
695
+ *
696
+ * @since 0.6.0
697
+ * @access public
698
+ * @return void
699
+ */
700
+ public function do_minute_hour_archive_items() {
701
+
702
+ /* Add $wp_rewrite->front to the trail. */
703
+ $this->do_rewrite_front_items();
704
+
705
+ /* Add the minute + hour item. */
706
+ if ( true === $this->args['show_title'] )
707
+ $this->items[] = get_the_time( $this->args['labels']['archive_minute_hour'] );
708
+ }
709
+
710
+ /**
711
+ * Adds the items to the trail items array for minute archives.
712
+ *
713
+ * @since 0.6.0
714
+ * @access public
715
+ * @return void
716
+ */
717
+ public function do_minute_archive_items() {
718
+
719
+ /* Add $wp_rewrite->front to the trail. */
720
+ $this->do_rewrite_front_items();
721
+
722
+ /* Add the minute item. */
723
+ if ( true === $this->args['show_title'] )
724
+ $this->items[] = sprintf( $this->args['labels']['archive_minute'], date_i18n( 'i', get_the_time( 'U' ) ) );
725
+ }
726
+
727
+ /**
728
+ * Adds the items to the trail items array for hour archives.
729
+ *
730
+ * @since 0.6.0
731
+ * @access public
732
+ * @return void
733
+ */
734
+ public function do_hour_archive_items() {
735
+
736
+ /* Add $wp_rewrite->front to the trail. */
737
+ $this->do_rewrite_front_items();
738
+
739
+ /* Add the hour item. */
740
+ if ( true === $this->args['show_title'] )
741
+ $this->items[] = get_the_time( $this->args['labels']['archive_hour'] );
742
+ }
743
+
744
+ /**
745
+ * Adds the items to the trail items array for day archives.
746
+ *
747
+ * @since 0.6.0
748
+ * @access public
749
+ * @return void
750
+ */
751
+ public function do_day_archive_items() {
752
+
753
+ /* Add $wp_rewrite->front to the trail. */
754
+ $this->do_rewrite_front_items();
755
+
756
+ /* Get year, month, and day. */
757
+ $year = get_the_time( $this->args['labels']['archive_year'] );
758
+ $month = get_the_time( $this->args['labels']['archive_month'] );
759
+ $day = get_the_time( $this->args['labels']['archive_day'] );
760
+
761
+ /* Add the year and month items. */
762
+ $this->items[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . esc_attr( $year ) . '">' . $year . '</a>';
763
+ $this->items[] = '<a href="' . get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) . '" title="' . esc_attr( $month ) . '">' . $month . '</a>';
764
+
765
+ /* Add the day item. */
766
+ if ( is_paged() )
767
+ $this->items[] = '<a href="' . get_day_link( get_the_time( 'Y' ), get_the_time( 'm' ), get_the_time( 'd' ) ) . '" title="' . esc_attr( $day ) . '">' . $day . '</a>';
768
+
769
+ elseif ( true === $this->args['show_title'] )
770
+ $this->items[] = $day;
771
+ }
772
+
773
+ /**
774
+ * Adds the items to the trail items array for week archives.
775
+ *
776
+ * @since 0.6.0
777
+ * @access public
778
+ * @return void
779
+ */
780
+ public function do_week_archive_items() {
781
+
782
+ /* Add $wp_rewrite->front to the trail. */
783
+ $this->do_rewrite_front_items();
784
+
785
+ /* Get the year and week. */
786
+ $year = get_the_time( $this->args['labels']['archive_year'] );
787
+ $week = sprintf( $this->args['labels']['archive_week'], date_i18n( 'W', get_the_time( 'U' ) ) );
788
+
789
+ /* Add the year item. */
790
+ $this->items[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . esc_attr( $year ) . '">' . $year . '</a>';
791
+
792
+ /* Add the week item. */
793
+ if ( is_paged() )
794
+ $this->items[] = get_archives_link( add_query_arg( array( 'm' => get_the_time( 'Y' ), 'w' => get_the_time( 'W' ) ), home_url() ), $week, false );
795
+
796
+ elseif ( true === $this->args['show_title'] )
797
+ $this->items[] = $week;
798
+ }
799
+
800
+ /**
801
+ * Adds the items to the trail items array for month archives.
802
+ *
803
+ * @since 0.6.0
804
+ * @access public
805
+ * @return void
806
+ */
807
+ public function do_month_archive_items() {
808
+
809
+ /* Add $wp_rewrite->front to the trail. */
810
+ $this->do_rewrite_front_items();
811
+
812
+ /* Get the year and month. */
813
+ $year = get_the_time( $this->args['labels']['archive_year'] );
814
+ $month = get_the_time( $this->args['labels']['archive_month'] );
815
+
816
+ /* Add the year item. */
817
+ $this->items[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . esc_attr( $year ) . '">' . $year . '</a>';
818
+
819
+ /* Add the month item. */
820
+ if ( is_paged() )
821
+ $this->items[] = '<a href="' . get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) . '" title="' . esc_attr( $month ) . '">' . $month . '</a>';
822
+
823
+ elseif ( true === $this->args['show_title'] )
824
+ $this->items[] = $month;
825
+ }
826
+
827
+ /**
828
+ * Adds the items to the trail items array for year archives.
829
+ *
830
+ * @since 0.6.0
831
+ * @access public
832
+ * @return void
833
+ */
834
+ public function do_year_archive_items() {
835
+
836
+ /* Add $wp_rewrite->front to the trail. */
837
+ $this->do_rewrite_front_items();
838
+
839
+ /* Get the year. */
840
+ $year = get_the_time( $this->args['labels']['archive_year'] );
841
+
842
+ /* Add the year item. */
843
+ if ( is_paged() )
844
+ $this->items[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . esc_attr( $year ) . '">' . $year . '</a>';
845
+
846
+ elseif ( true === $this->args['show_title'] )
847
+ $this->items[] = $year;
848
+ }
849
+
850
+ /**
851
+ * Adds the items to the trail items array for archives that don't have a more specific method
852
+ * defined in this class.
853
+ *
854
+ * @since 0.6.0
855
+ * @access public
856
+ * @return void
857
+ */
858
+ public function do_default_archive_items() {
859
+
860
+ /* If this is a date-/time-based archive, add $wp_rewrite->front to the trail. */
861
+ if ( is_date() || is_time() )
862
+ $this->do_rewrite_front_items();
863
+
864
+ if ( true === $this->args['show_title'] )
865
+ $this->items[] = $this->args['labels']['archives'];
866
+ }
867
+
868
+ /**
869
+ * Adds the items to the trail items array for search results.
870
+ *
871
+ * @since 0.6.0
872
+ * @access public
873
+ * @return void
874
+ */
875
+ public function do_search_items() {
876
+
877
+ if ( is_paged() )
878
+ $this->items[] = '<a href="' . get_search_link() . '" title="' . esc_attr( sprintf( $this->args['labels']['search'], get_search_query() ) ) . '">' . sprintf( $this->args['labels']['search'], get_search_query() ) . '</a>';
879
+
880
+ elseif ( true === $this->args['show_title'] )
881
+ $this->items[] = sprintf( $this->args['labels']['search'], get_search_query() );
882
+ }
883
+
884
+ /**
885
+ * Adds the items to the trail items array for 404 pages.
886
+ *
887
+ * @since 0.6.0
888
+ * @access public
889
+ * @return void
890
+ */
891
+ public function do_404_items() {
892
+
893
+ if ( true === $this->args['show_title'] )
894
+ $this->items[] = $this->args['labels']['error_404'];
895
+ }
896
+
897
+ /**
898
+ * Get parent posts by path. Currently, this method only supports getting parents of the 'page'
899
+ * post type. The goal of this function is to create a clear path back to home given what would
900
+ * normally be a "ghost" directory. If any page matches the given path, it'll be added.
901
+ *
902
+ * @since 0.6.0
903
+ * @access public
904
+ * @param string $path The path (slug) to search for posts by.
905
+ * @return void
906
+ */
907
+ function do_path_parents( $path ) {
908
+
909
+ /* Trim '/' off $path in case we just got a simple '/' instead of a real path. */
910
+ $path = trim( $path, '/' );
911
+
912
+ /* If there's no path, return. */
913
+ if ( empty( $path ) )
914
+ return;
915
+
916
+ /* Get parent post by the path. */
917
+ $post = get_page_by_path( $path );
918
+
919
+ if ( !empty( $post ) ) {
920
+ $this->do_post_parents( $post->ID );
921
+ }
922
+
923
+ elseif ( is_null( $post ) ) {
924
+
925
+ /* Separate post names into separate paths by '/'. */
926
+ $path = trim( $path, '/' );
927
+ preg_match_all( "/\/.*?\z/", $path, $matches );
928
+
929
+ /* If matches are found for the path. */
930
+ if ( isset( $matches ) ) {
931
+
932
+ /* Reverse the array of matches to search for posts in the proper order. */
933
+ $matches = array_reverse( $matches );
934
+
935
+ /* Loop through each of the path matches. */
936
+ foreach ( $matches as $match ) {
937
+
938
+ /* If a match is found. */
939
+ if ( isset( $match[0] ) ) {
940
+
941
+ /* Get the parent post by the given path. */
942
+ $path = str_replace( $match[0], '', $path );
943
+ $post = get_page_by_path( trim( $path, '/' ) );
944
+
945
+ /* If a parent post is found, set the $post_id and break out of the loop. */
946
+ if ( !empty( $post ) && 0 < $post->ID ) {
947
+ $this->do_post_parents( $post->ID );
948
+ break;
949
+ }
950
+ }
951
+ }
952
+ }
953
+ }
954
+ }
955
+
956
+ /**
957
+ * Searches for term parents of hierarchical taxonomies. This function is similar to the WordPress
958
+ * function get_category_parents() but handles any type of taxonomy.
959
+ *
960
+ * @since 0.6.0
961
+ * @param int $term_id ID of the term to get the parents of.
962
+ * @param string $taxonomy Name of the taxonomy for the given term.
963
+ * @return void
964
+ */
965
+ function do_term_parents( $term_id, $taxonomy ) {
966
+
967
+ /* Set up some default arrays. */
968
+ $parents = array();
969
+
970
+ /* While there is a parent ID, add the parent term link to the $parents array. */
971
+ while ( $term_id ) {
972
+
973
+ /* Get the parent term. */
974
+ $term = get_term( $term_id, $taxonomy );
975
+
976
+ /* Add the formatted term link to the array of parent terms. */
977
+ $parents[] = '<a href="' . get_term_link( $term, $taxonomy ) . '" title="' . esc_attr( $term->name ) . '">' . $term->name . '</a>';
978
+
979
+ /* Set the parent term's parent as the parent ID. */
980
+ $term_id = $term->parent;
981
+ }
982
+
983
+ /* If we have parent terms, reverse the array to put them in the proper order for the trail. */
984
+ if ( !empty( $parents ) )
985
+ $this->items = array_merge( $this->items, $parents );
986
+ }
987
+
988
+ /**
989
+ * Turns %tag% from permalink structures into usable links for the breadcrumb trail. This feels kind of
990
+ * hackish for now because we're checking for specific %tag% examples and only doing it for the 'post'
991
+ * post type. In the future, maybe it'll handle a wider variety of possibilities, especially for custom post
992
+ * types.
993
+ *
994
+ * @since 0.6.0
995
+ * @access public
996
+ * @param int $post_id ID of the post whose parents we want.
997
+ * @param string $path Path of a potential parent page.
998
+ * @param array $args Mixed arguments for the menu.
999
+ * @return array
1000
+ */
1001
+ public function map_rewrite_tags( $post_id, $path ) {
1002
+
1003
+ /* Get the post based on the post ID. */
1004
+ $post = get_post( $post_id );
1005
+
1006
+ /* If no post is returned, an error is returned, or the post does not have a 'post' post type, return. */
1007
+ if ( empty( $post ) || is_wp_error( $post ) || 'post' !== $post->post_type )
1008
+ return $trail;
1009
+
1010
+ /* Trim '/' from both sides of the $path. */
1011
+ $path = trim( $path, '/' );
1012
+
1013
+ /* Split the $path into an array of strings. */
1014
+ $matches = explode( '/', $path );
1015
+
1016
+ /* If matches are found for the path. */
1017
+ if ( is_array( $matches ) ) {
1018
+
1019
+ /* Loop through each of the matches, adding each to the $trail array. */
1020
+ foreach ( $matches as $match ) {
1021
+
1022
+ /* Trim any '/' from the $match. */
1023
+ $tag = trim( $match, '/' );
1024
+
1025
+ /* If using the %year% tag, add a link to the yearly archive. */
1026
+ if ( '%year%' == $tag )
1027
+ $this->items[] = '<a href="' . get_year_link( get_the_time( 'Y', $post_id ) ) . '" title="' . get_the_time( __( 'Y', 'breadcrumb-trail' ), $post_id ) . '">' . get_the_time( $this->args['labels']['archive_year'], $post_id ) . '</a>';
1028
+
1029
+ /* If using the %monthnum% tag, add a link to the monthly archive. */
1030
+ elseif ( '%monthnum%' == $tag )
1031
+ $this->items[] = '<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', 'breadcrumb-trail' ), $post_id ) . '">' . get_the_time( $this->args['labels']['archive_month'], $post_id ) . '</a>';
1032
+
1033
+ /* If using the %day% tag, add a link to the daily archive. */
1034
+ elseif ( '%day%' == $tag )
1035
+ $this->items[] = '<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', 'breadcrumb-trail' ), $post_id ) . '">' . get_the_time( $this->args['labels']['archive_day'], $post_id ) . '</a>';
1036
+
1037
+ /* If using the %author% tag, add a link to the post author archive. */
1038
+ elseif ( '%author%' == $tag )
1039
+ $this->items[] = '<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>';
1040
+
1041
+ /* If using the %category% tag, add a link to the first category archive to match permalinks. */
1042
+ elseif ( '%category%' == $tag ) {
1043
+
1044
+ /* Force override terms in this post type. */
1045
+ $this->args['post_taxonomy'][ $post->post_type ] = false;
1046
+
1047
+ /* Get the post categories. */
1048
+ $terms = get_the_category( $post_id );
1049
+
1050
+ /* Check that categories were returned. */
1051
+ if ( $terms ) {
1052
+
1053
+ /* Sort the terms by ID and get the first category. */
1054
+ usort( $terms, '_usort_terms_by_ID' );
1055
+ $term = get_term( $terms[0], 'category' );
1056
+
1057
+ /* If the category has a parent, add the hierarchy to the trail. */
1058
+ if ( 0 < $term->parent )
1059
+ $this->do_term_parents( $term->parent, 'category' );
1060
+
1061
+ /* Add the category archive link to the trail. */
1062
+ $this->items[] = '<a href="' . get_term_link( $term, 'category' ) . '" title="' . esc_attr( $term->name ) . '">' . $term->name . '</a>';
1063
+ }
1064
+ }
1065
+ }
1066
+ }
1067
+ }
1068
+ }
1069
+
1070
+ /**
1071
+ * Extends the Breadcrumb_Trail class for bbPress. Only use this if bbPress is in use. This should
1072
+ * serve as an example for other plugin developers to build custom breadcrumb items.
1073
+ *
1074
+ * @since 0.6.0
1075
+ * @access public
1076
+ */
1077
+ class bbPress_Breadcrumb_Trail extends Breadcrumb_Trail {
1078
+
1079
+ /**
1080
+ * Runs through the various bbPress conditional tags to check the current page being viewed. Once
1081
+ * a condition is met, add items to the $items array.
1082
+ *
1083
+ * @since 0.6.0
1084
+ * @access public
1085
+ * @return void
1086
+ */
1087
+ public function do_trail_items() {
1088
+
1089
+ /* Get the forum post type object. */
1090
+ $post_type_object = get_post_type_object( bbp_get_forum_post_type() );
1091
+
1092
+ /* If not viewing the forum root/archive page and a forum archive exists, add it. */
1093
+ if ( !empty( $post_type_object->has_archive ) && !bbp_is_forum_archive() )
1094
+ $this->items[] = '<a href="' . get_post_type_archive_link( bbp_get_forum_post_type() ) . '">' . bbp_get_forum_archive_title() . '</a>';
1095
+
1096
+ /* If viewing the forum root/archive. */
1097
+ if ( bbp_is_forum_archive() ) {
1098
+
1099
+ if ( true === $this->args['show_title'] )
1100
+ $this->items[] = bbp_get_forum_archive_title();
1101
+ }
1102
+
1103
+ /* If viewing the topics archive. */
1104
+ elseif ( bbp_is_topic_archive() ) {
1105
+
1106
+ if ( true === $this->args['show_title'] )
1107
+ $this->items[] = bbp_get_topic_archive_title();
1108
+ }
1109
+
1110
+ /* If viewing a topic tag archive. */
1111
+ elseif ( bbp_is_topic_tag() ) {
1112
+
1113
+ if ( true === $this->args['show_title'] )
1114
+ $this->items[] = bbp_get_topic_tag_name();
1115
+ }
1116
+
1117
+ /* If viewing a topic tag edit page. */
1118
+ elseif ( bbp_is_topic_tag_edit() ) {
1119
+ $this->items[] = '<a href="' . bbp_get_topic_tag_link() . '">' . bbp_get_topic_tag_name() . '</a>';
1120
+
1121
+ if ( true === $this->args['show_title'] )
1122
+ $this->items[] = __( 'Edit', 'breadcrumb-trail' );
1123
+ }
1124
+
1125
+ /* If viewing a "view" page. */
1126
+ elseif ( bbp_is_single_view() ) {
1127
+
1128
+ if ( true === $this->args['show_title'] )
1129
+ $this->items[] = bbp_get_view_title();
1130
+ }
1131
+
1132
+ /* If viewing a single topic page. */
1133
+ elseif ( bbp_is_single_topic() ) {
1134
+
1135
+ /* Get the queried topic. */
1136
+ $topic_id = get_queried_object_id();
1137
+
1138
+ /* Get the parent items for the topic, which would be its forum (and possibly forum grandparents). */
1139
+ $this->do_post_parents( bbp_get_topic_forum_id( $topic_id ) );
1140
+
1141
+ /* If viewing a split, merge, or edit topic page, show the link back to the topic. Else, display topic title. */
1142
+ if ( bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit() )
1143
+ $this->items[] = '<a href="' . bbp_get_topic_permalink( $topic_id ) . '">' . bbp_get_topic_title( $topic_id ) . '</a>';
1144
+
1145
+ elseif ( true === $this->args['show_title'] )
1146
+ $this->items[] = bbp_get_topic_title( $topic_id );
1147
+
1148
+ /* If viewing a topic split page. */
1149
+ if ( bbp_is_topic_split() && true === $this->args['show_title'] )
1150
+ $this->items[] = __( 'Split', 'breadcrumb-trail' );
1151
+
1152
+ /* If viewing a topic merge page. */
1153
+ elseif ( bbp_is_topic_merge() && true === $this->args['show_title'] )
1154
+ $this->items[] = __( 'Merge', 'breadcrumb-trail' );
1155
+
1156
+ /* If viewing a topic edit page. */
1157
+ elseif ( bbp_is_topic_edit() && true === $this->args['show_title'] )
1158
+ $this->items[] = __( 'Edit', 'breadcrumb-trail' );
1159
+ }
1160
+
1161
+ /* If viewing a single reply page. */
1162
+ elseif ( bbp_is_single_reply() ) {
1163
+
1164
+ /* Get the queried reply object ID. */
1165
+ $reply_id = get_queried_object_id();
1166
+
1167
+ /* Get the parent items for the reply, which should be its topic. */
1168
+ $this->do_post_parents( bbp_get_reply_topic_id( $reply_id ) );
1169
+
1170
+ /* If viewing a reply edit page, link back to the reply. Else, display the reply title. */
1171
+ if ( bbp_is_reply_edit() ) {
1172
+ $this->items[] = '<a href="' . bbp_get_reply_url( $reply_id ) . '">' . bbp_get_reply_title( $reply_id ) . '</a>';
1173
+
1174
+ if ( true === $this->args['show_title'] )
1175
+ $this->items[] = __( 'Edit', 'breadcrumb-trail' );
1176
+
1177
+ } elseif ( true === $this->args['show_title'] ) {
1178
+ $this->items[] = bbp_get_reply_title( $reply_id );
1179
+ }
1180
+
1181
+ }
1182
+
1183
+ /* If viewing a single forum. */
1184
+ elseif ( bbp_is_single_forum() ) {
1185
+
1186
+ /* Get the queried forum ID and its parent forum ID. */
1187
+ $forum_id = get_queried_object_id();
1188
+ $forum_parent_id = bbp_get_forum_parent_id( $forum_id );
1189
+
1190
+ /* If the forum has a parent forum, get its parent(s). */
1191
+ if ( 0 !== $forum_parent_id)
1192
+ $this->do_post_parents( $forum_parent_id );
1193
+
1194
+ /* Add the forum title to the end of the trail. */
1195
+ if ( true === $this->args['show_title'] )
1196
+ $this->items[] = bbp_get_forum_title( $forum_id );
1197
+ }
1198
+
1199
+ /* If viewing a user page or user edit page. */
1200
+ elseif ( bbp_is_single_user() || bbp_is_single_user_edit() ) {
1201
+
1202
+ if ( bbp_is_single_user_edit() ) {
1203
+ $this->items[] = '<a href="' . bbp_get_user_profile_url() . '">' . bbp_get_displayed_user_field( 'display_name' ) . '</a>';
1204
+
1205
+ if ( true === $this->args['show_title'] )
1206
+ $this->items[] = __( 'Edit', 'breadcrumb-trail' );
1207
+ } elseif ( true === $this->args['show_title'] ) {
1208
+ $this->items[] = bbp_get_displayed_user_field( 'display_name' );
1209
+ }
1210
+ }
1211
+
1212
+ /* Return the bbPress breadcrumb trail items. */
1213
+ $this->items = apply_filters( 'breadcrumb_trail_get_bbpress_items', $this->items, $this->args );
1214
+ }
1215
+ }
1216
+
1217
+ ?>
languages/breadcrumb-trail.pot ADDED
@@ -0,0 +1,93 @@