Created
October 16, 2016 21:05
-
-
Save stephanieleary/4f592e462ea51866082a099b11c6309d to your computer and use it in GitHub Desktop.
Genesis breadcrumbs for tag1+tag2 or tag1,tag2 combined term archives
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Display titles of all terms in combined term archive breadcrumbs (tag1+tag2 or tag1,tag2) | |
function scl_multiple_tax_breadcrumbs( $crumbs, $args ) { | |
if ( !is_tax() ) | |
return $crumbs; | |
$taxonomy = get_query_var( 'taxonomy' ); | |
$topics = get_query_var( $taxonomy ); | |
if ( empty( $topics ) ) | |
return $crumbs; | |
$hascomma = strpos( $topics, ',' ); | |
$hasplus = strpos( $topics, '+' ); | |
if ( $hascomma !== false OR $hasplus !== false ) { | |
if ( $hascomma ) { | |
$sep = ','; | |
$glue = ' or '; | |
} | |
else { | |
$sep = '+'; | |
$glue = ' and '; | |
} | |
$crumb = end( $crumbs ); | |
$linkedcrumbs = substr( $crumb, 0, strrpos( $crumb, $args['sep'] ) ); | |
$newcrumbs = array(); | |
$terms = explode( $sep, $topics ); | |
foreach ( $terms as $term ) { | |
$termobj = get_term_by( 'slug', $term, 'work_zone_topics' ); | |
$newcrumbs[] = $termobj->name; | |
} | |
$crumbs = array( $linkedcrumbs, implode( $glue, $newcrumbs ) ); | |
} | |
return $crumbs; | |
} | |
add_filter( 'genesis_build_crumbs', 'scl_multiple_tax_breadcrumbs', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment