admin管理员组文章数量:1122846
Here is the code for the category breakcrumb:
/* Display breadcrumbs for single post */
$count_loop = NULL;
$count_categories = NULL;
if ( is_single() ) {
$category = get_the_category();
$num_cat = count($category);
if ($num_cat <=1) {
$output .= ' ' . html_entity_decode( esc_html( get_the_title() ) );
} else {
// Count Total categories
foreach( get_the_category() as $category) {
$count_categories++;
}
// Output Categories
foreach( get_the_category() as $category) {
$count_loop++;
if ( $count_loop < $count_categories ) {
$output .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->cat_name ) . '</a>' . $delimiter_inner;
} else {
$output .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->cat_name ) . '</a>';
}
}
if (strlen(get_the_title()) >= $maxLength) {
$output .= ' ' . $delimiter . esc_html( trim( substr( get_the_title(), 0, $maxLength ) ) ) . ' …';
} else {
$output .= ' ' . $delimiter . esc_html( get_the_title() );
}
}
}
For example, a post with 4 categories gives me: Base / Campaign / News / Tools / and the post title.
It works fine. However, it retrieves the result ordered by name. I would like to have it in a hierarchical order, considering that some of them are not children...
I expected having: News / Base > Tools > Campaign > post title.
Any idea how I can manage this with this piece of code I already have? Among others, I tried this:
$category = get_the_category();
$category = array_reverse( $category );
And this:
get_category_parents( $category, true, ' > ' );
Without any success. Thx for your help.
本文标签: Categories breadcrumb in a hierarchical order
版权声明:本文标题:Categories breadcrumb in a hierarchical order 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736297124a1929944.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论