Revisions
- April 29, 2012 @ 14:28:18 [Current Revision] by PeterLugg
- April 29, 2012 @ 14:26:24 by PeterLugg
Revision Differences
April 29, 2012 @ 14:26:24 | Current Revision | ||
---|---|---|---|
Content | |||
Added: Taken from: http:/ /www.free-php.net/ 780/wordpress- custom-taxonomy- breadcrumbs/ | |||
Added: While developing a theme that uses custom taxonomies and custom post types, I ran across the need to include breadcrumb navigation to the custom taxonomies. After a couple of days of searching around and not finding any real solutions, I ended up creating my own function to do it. | |||
Added: Simply copy this to your functions.php file: | |||
Added: [php] | |||
Added: <?php | |||
Added: function postTypeCrumbs($postType, $postTax) { | |||
Added: $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); | |||
Added: $taxonomy = get_taxonomy( $term->taxonomy); | |||
Added: $parents = get_ancestors( $term->term_id, $postTax ); | |||
Added: $parents = array_reverse($parents); | |||
Added: $archive_link = get_post_type_ archive_link( $postType ); | |||
Added: echo '<ul class="ax_ crumbs">'; | |||
Added: if ($taxonomy) { | |||
Added: echo '<li><a href="' . $archive_link . '" title="' . $taxonomy-> labels->name . '">' . $taxonomy-> labels->name . '</a> &raquo; </li>'; | |||
Added: } | |||
Added: foreach ( $parents as $parent ) { | |||
Added: $p = get_term( $parent, $postTax ); | |||
Added: echo '<li><a href="' . get_term_link( $p->slug, $postTax) . '" title="' . $p->name . '">' . $p->name . '</a> <span>& raquo;</span> </li>'; | |||
Added: } | |||
Added: if ($term) { | |||
Added: echo '<li>' . $term->name . '</li>'; | |||
Added: } | |||
Added: echo '</ul>'; | |||
Deleted: | Added: } | ||
Added: ?> | |||
Added: [/php] | |||
Added: Paste this where ever you would like the taxonomy to display. | |||
Added: [php] | |||
Added: <?php postTypeCrumbs('post type', 'taxonomy name'); ?> | |||
Added: [/php] |
Note: Spaces may be added to comparison text to allow better line wrapping.
No comments yet.