Php 加入“;“家”;在面包屑的开始

Php 加入“;“家”;在面包屑的开始,php,wordpress,woocommerce,styles,breadcrumbs,Php,Wordpress,Woocommerce,Styles,Breadcrumbs,我在临时站点上设置面包屑的格式时遇到问题。我以前让他们设置了正确的类别,但是父类别一直显示错误的类别(我确实修复了,但是…)。修复导致“主页”选项消失。我不懂任何php,一直在尝试如何在分类前的每个页面上添加“Home/”选项,但没有成功。下面是我现在使用的代码。有人有什么想法吗 if ( ! empty( $breadcrumb ) ) { echo $wrap_before; if ( is_single() && get_post_type() == '

我在临时站点上设置面包屑的格式时遇到问题。我以前让他们设置了正确的类别,但是父类别一直显示错误的类别(我确实修复了,但是…)。修复导致“主页”选项消失。我不懂任何php,一直在尝试如何在分类前的每个页面上添加“Home/”选项,但没有成功。下面是我现在使用的代码。有人有什么想法吗

if ( ! empty( $breadcrumb ) ) {

    echo $wrap_before;

    if ( is_single() && get_post_type() == 'product' ) {

        echo $prepend;

        if ( $terms = get_the_terms( $post->ID, 'product_cat' ) ) {

            $referer = wp_get_referer();

            $printed = array();

            foreach( $terms as $term){

                if(in_array($term->id, $printed)) continue;

                $referer_slug = (strpos($referer, '/'.$term->slug.'/'));

                if(!$referer_slug==false){

                    $printed[] = $term->id;

                    $category_name = $term->name;
                    $ancestors = get_ancestors( $term->term_id, 'product_cat' );
                    $ancestors = array_reverse( $ancestors );

                    foreach ( $ancestors as $ancestor ) {
                        $ancestor = get_term( $ancestor, 'product_cat' );

                        if ( ! is_wp_error( $ancestor ) && $ancestor )
                            echo $before . '<a href="' . get_term_link( $ancestor->slug, 'product_cat' ) . '">' . $ancestor->name . '</a>' . $after . $delimiter;
                    }

                    echo $before . '<a href="' . get_term_link( $term->slug, 'product_cat' ) . '">' . $category_name . '</a>' . $after . $delimiter;
                }
            }

        }

        echo $before . get_the_title() . $after;

    } else {

        foreach ( $breadcrumb as $key => $crumb ) {

            echo $before;

            if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
                echo '<a href="' . esc_url( $crumb[1] ) . '">' . esc_html( $crumb[0] ) . '</a>';
            } else {
                echo esc_html( $crumb[0] );
            }

            echo $after;

            if ( sizeof( $breadcrumb ) !== $key + 1 ) {
                echo $delimiter;
            }

        }
    }

    echo $wrap_after;

}
if(!empty($breadcrumb)){
回音$wrap_;
if(is_single()&&get_post_type()='product'){
echo$prepend;
如果($terms=get_the_terms($post->ID,'product_cat')){
$referer=wp_get_referer();
$printed=array();
foreach($terms作为$term){
如果(在数组中($term->id,$printed))继续;
$referer_slug=(strpos($referer'/'.$term->slug'/');
如果(!$referer\u slug==false){
$printed[]=$term->id;
$category_name=$term->name;
$祖先=获取祖先($term->term_id,'product_cat');
$ANCENTERS=数组\反向($ANCENTERS);
foreach($祖先作为$祖先){
$ANCENTOR=get_术语($ANCENTOR,'product_cat');
如果(!is_wp_error($祖先)&&$祖先)
回显$before.''.$after.$delimiter;
}
回显$before.''.$after.$delimiter;
}
}
}
echo$before.get_the_title().$after;
}否则{
foreach($key=>$crumb的面包屑){
回音$before;
如果(!empty($crump[1])&&sizeof($breadcrumb)!==$key+1){
回声';
}否则{
echo esc_html($crumb[0]);
}
echo$after;
if(sizeof($breadcrumb)!=$key+1){
echo$分隔符;
}
}
}
回音$wrap_后;
}

提前谢谢你的帮助

我认为您可以通过更改以下行来实现这一点
echo$wrap\u到此:

echo $wrap_before.'<a href="/" title="Home">Home</a> »';
echo$wrap_before.'»;

为什么不总是在开始时以“硬编码”的形式打印回家?在面包屑的开头有家不是件小事吗?我想从一开始就把它硬编码,但我不懂php。添加该选项的代码是什么?请参见下面我的解决方案,此解决方案已修复!!非常感谢你,我感谢你的帮助!