首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >数组拼接不保留"trail_end“

数组拼接不保留"trail_end“
EN

Stack Overflow用户
提问于 2012-01-31 17:44:10
回答 1查看 165关注 0票数 2

我是个新手,有一段Wordpress代码,里面有一个小问题。

很抱歉,如果我的问题是愚蠢的,虽然支持我购买的主题似乎是一个很大的延迟回答。

我会粘贴它也许有人能帮上忙。如果没有人能解决这个问题,我将删除这个问题。

该代码为我的上的面包屑导航添加了一些更改。

我认为的问题是:

代码语言:javascript
复制
// Add the trail back on to the end.
$links[] = $trail['trail_end'];

// Add the new links, and the original trail's end, back into the trail.
array_splice( $trail, 1, count( $trail ) - 1, $links );

这两行代码应该在单词“Xtreme”(在我的链接示例中)后面的面包屑末尾添加一个<span class="trail-end"></span> (在我的链接示例中)

以下是代码:

代码语言:javascript
复制
function woo_custom_breadcrumbs_trail_add_product_categories ( $trail ) {
    if ( ( get_post_type() == 'product' ) && is_singular() ) {
        global $post;

        $taxonomy = 'product_cat';

        $terms = get_the_terms( $post->ID, $taxonomy );
        $links = array();

        if ( $terms && ! is_wp_error( $terms ) ) {
            foreach ( $terms as $c ) {
                $parents = woo_get_term_parents( $c->term_id, $taxonomy, true, ', ', $c->name, array() );

                if ( $parents != '' && ! is_wp_error( $parents ) ) {
                    $parents_arr = explode( ', ', $parents );

                    foreach ( $parents_arr as $p ) {
                        if ( $p != '' ) { $links[] = $p; }
                    }
                }
            }

            // Add the trail back on to the end.
            $links[] = $trail['trail_end'];


            // Add the new links, and the original trail's end, back into the trail.
            array_splice( $trail, 1, count( $trail ) - 1, $links );

        }
    }

    return $trail;
} // End woo_custom_breadcrumbs_trail_add_product_categories()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-31 21:56:37

试试这个:

代码语言:javascript
复制
...

// Wrap the trail_end with your span tag
$trail['trail_end'] = '<span class="trail-end">' . end($trail) . '</span>';

// Add the trail back on to the end.
$links[] = $trail['trail_end'];

...

记住,这是一个黑客,我建议在渲染面包屑的模板中这样做。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9084315

复制
相关文章

相似问题

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