首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在breadcrumbs开头添加"Home“

在breadcrumbs开头添加"Home“
EN

Stack Overflow用户
提问于 2020-01-12 06:29:53
回答 1查看 60关注 0票数 0

我在我的临时站点上格式化面包屑时遇到了问题。我之前用正确的类别设置了它们,但父类别一直显示错误的类别(我确实修复了,但是...)。修复导致"home“选项消失。我不知道任何php,并且一直试图弄清楚如何在每个页面的类别前添加一个"Home /“选项,但没有成功。下面是我现在使用的代码。有谁有什么想法吗?

代码语言:javascript
复制
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;

}

提前感谢您的帮助!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-13 03:03:35

我认为您可以通过将以下行的echo $wrap_before;更改为以下代码来实现此目的:

代码语言:javascript
复制
echo $wrap_before.'<a href="/" title="Home">Home</a> »';
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59699207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档