/
www
/
wwwroot
/
fxdst.com
/
wp-content
/
themes
/
fxdst
/
templates
/
Upload File
HOME
<?php if ( ! defined( 'ABSPATH' ) ) { exit; } if ( is_front_page() || is_home() ) { return; } $items = array( array( 'label' => '首页', 'url' => home_url( '/' ), ), ); $fxdst_add_term_chain = function ( $term ) use ( &$items ) { if ( ! $term || is_wp_error( $term ) ) { return; } $ancestors = array_reverse( get_ancestors( $term->term_id, $term->taxonomy ) ); foreach ( $ancestors as $ancestor_id ) { $ancestor = get_term( $ancestor_id, $term->taxonomy ); if ( $ancestor && ! is_wp_error( $ancestor ) ) { $items[] = array( 'label' => $ancestor->name, 'url' => get_term_link( $ancestor ), ); } } $items[] = array( 'label' => $term->name, 'url' => get_term_link( $term ), ); }; if ( is_tax( 'favorites' ) ) { $fxdst_add_term_chain( get_queried_object() ); } elseif ( is_singular( 'sites' ) ) { $terms = get_the_terms( get_the_ID(), 'favorites' ); if ( $terms && ! is_wp_error( $terms ) ) { usort( $terms, function ( $a, $b ) { return count( get_ancestors( $b->term_id, 'favorites' ) ) - count( get_ancestors( $a->term_id, 'favorites' ) ); } ); $fxdst_add_term_chain( $terms[0] ); } $items[] = array( 'label' => get_the_title() ); } elseif ( is_page() ) { $ancestors = array_reverse( get_post_ancestors( get_the_ID() ) ); foreach ( $ancestors as $ancestor_id ) { $items[] = array( 'label' => get_the_title( $ancestor_id ), 'url' => get_permalink( $ancestor_id ), ); } $items[] = array( 'label' => get_the_title() ); } elseif ( is_search() ) { $items[] = array( 'label' => '搜索:' . get_search_query() ); } elseif ( is_404() ) { $items[] = array( 'label' => '404' ); } elseif ( is_category() || is_tag() || is_tax() ) { $queried = get_queried_object(); if ( $queried instanceof WP_Term ) { $fxdst_add_term_chain( $queried ); } } elseif ( is_singular() ) { $categories = get_the_category(); if ( ! empty( $categories ) ) { $cat = $categories[0]; $ancestors = array_reverse( get_ancestors( $cat->term_id, 'category' ) ); foreach ( $ancestors as $ancestor_id ) { $ancestor = get_category( $ancestor_id ); if ( $ancestor && ! is_wp_error( $ancestor ) ) { $items[] = array( 'label' => $ancestor->name, 'url' => get_category_link( $ancestor ), ); } } $items[] = array( 'label' => $cat->name, 'url' => get_category_link( $cat ), ); } $items[] = array( 'label' => get_the_title() ); } elseif ( is_post_type_archive() ) { $items[] = array( 'label' => post_type_archive_title( '', false ) ); } elseif ( is_author() ) { $items[] = array( 'label' => get_the_author_meta( 'display_name', get_query_var( 'author' ) ) ); } elseif ( is_date() ) { $items[] = array( 'label' => get_the_archive_title() ); } else { $items[] = array( 'label' => wp_get_document_title() ); } if ( count( $items ) < 2 ) { return; } ?> <div class="fxdst-breadcrumb-wrap"> <nav class="fxdst-breadcrumb" aria-label="Breadcrumb"> <ol> <?php foreach ( $items as $index => $item ) : ?> <?php $is_last = ( $index === count( $items ) - 1 ); ?> <li> <?php if ( ! $is_last && ! empty( $item['url'] ) && ! is_wp_error( $item['url'] ) ) : ?> <a href="<?php echo esc_url( $item['url'] ); ?>"><?php echo wp_kses_post( $item['label'] ); ?></a> <?php else : ?> <span><?php echo wp_kses_post( $item['label'] ); ?></span> <?php endif; ?> </li> <?php endforeach; ?> </ol> </nav> </div>