CG
(@du-bist-der-lenz)
ECサイトの商品ページのカテゴリー・リンクは、複数のパンくずを生成しているんですね。
こちらのトピックが参考になると思います。
https://ja.wordpress.org/support/topic/ネットショップのような複数のパンくずリストを/
Breadcrumb NavXT プラグインのフックを駆使すればできないことはないかもしれませんが、ほぼまるまるパンくずリストを作成することになるので自作した方が早いと思います。
タクソノミーをパンくずリスト風に表示する、サンプルコードを書いてみました。参考までに。
テンプレートに、
<div class="breadcrumbs">
<?php if ( function_exists( 'bcn_display' ) ) { bcn_display(); } ?>
</div>
<div class="breadcrumbs-sub1">
<?php echo get_the_breadcrumb_taxonomy( 'タクソノミー1' ); ?>
</div>
<div class="breadcrumbs-sub2">
<?php echo get_the_breadcrumb_taxonomy( 'タクソノミー2' ); ?>
</div>
functions.php に、
function get_the_breadcrumb_taxonomy( $taxonomy = 'category' ) {
$post_id = get_the_ID();
$breadcrumbs = array();
$breadcrumbs[] = array( 'title' => 'TOP', 'link' => home_url( '/' ) );
$terms = get_the_terms( $post_id, $taxonomy );
if ( $terms && ! is_wp_error( $terms ) ) {
$descendant_term = $terms[0];
if ( count( $terms ) > 1) {
foreach ( $terms as $key => $term ) {
foreach ( $terms as $term2 ) {
if ( term_is_ancestor_of( $term->term_id, $term2->term_id, $taxonomy ) ) {
$descendant_term = $term2;
break;
}
}
}
}
$term_ids = array_reverse( get_ancestors( $descendant_term->term_id, $taxonomy ) );
foreach ( $term_ids as $term_id ) {
$term = get_term( $term_id, $taxonomy );
$breadcrumbs[] = array( 'title' => $term->name, 'link' => get_term_link( $term_id ) );
}
$breadcrumbs[] = array( 'title' => $descendant_term->name, 'link' => get_term_link( $descendant_term->term_id ) );
}
$output = '';
foreach ( $breadcrumbs as $breadcrumb ) {
$output .= sprintf( '<span><a href="%1$s" title="%2$s"><span property="name">%2$s</span></a></span> > ',
esc_url( $breadcrumb['link'] ),
esc_html( $breadcrumb['title'] )
);
}
$output .= '<span>' . get_the_title() . '</span>';
return $output;
}
>ishitaka
コードまで書いていただきありがとうございます!これを参考に試してみます!