Breadcrumbs for sub-categories. #86

Closed
weavertheme opened this Issue Nov 16, 2012 · 0 comments

Comments

Projects
None yet
2 participants

I used your oenology breadcrumb code in Weaver, and a user just found a subtle bug when you have sub-categories. For example, if you create a category Photography, and two sub categories: Event and Wedding (alphabetical order is important to demo the bug), and then create two posts, one with Photography and Event, the other with Photography and Wedding, the breadcrumb won't display correctly for one of them.

Here's the fix (for line 952 of custom.php):

// Define Category Hierarchy Crumbs for Single Posts
elseif ( is_single() && !is_attachment() ) {
$cats = get_the_category();
if ($cats)
    $cur_cat = $cats[0];
else
    $cur_cat = '';
foreach ($cats as $cat) {
    $children = get_categories( array ('parent' => $cat->term_id ));
    if (count($children) == 0) {
    $cur_cat = $cat;
    break;
    }
}
if ($cur_cat) {
    $hierarchy = $delimiter . get_category_parents( $cur_cat, TRUE, $delimiter );
} else {
    $hierarchy = $delimiter . '';
}
    // Note: get_the_title() is filtered to output a
    // default title if none is specified
    $currentLocation = get_the_title();

}

The problem was the old $cat[0] didn't always get the lowest level category - the list was alphabetically sorted at that point, so you have to explicitly search for the bottom category.

Bruce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment