php – Woocommerce breadcrumbs多个类别
发布时间:2020-12-13 22:54:01 所属栏目:PHP教程 来源:网络整理
导读:我在wordpress有电子商务网站.里面有很多产品许多产品属于600多个类别.电源银行属于汽车,IT,媒体等.我的问题是,当我去那里的产品细节时,它默认只选择一个类别,无论是通过IT类别在最后它显示我这样的汽车Home / Shop / industry / Automobile / 600 mah Power
我在wordpress有电子商务网站.里面有很多产品&许多产品属于600多个类别.电源银行属于汽车,IT,媒体等.我的问题是,当我去那里的产品细节时,它默认只选择一个类别,无论是通过IT类别在最后它显示我这样的汽车Home / Shop / industry / Automobile / 600 mah Power Bank.但我通过IT去了这个产品,所以它应该像我这样的Home / Shop / industry / IT / 600 mah Power Bank.
如何从上一页来到我的路径? 解决方法
如果您正在使用Woocommerce,您可以直接使用以下内容,如果不是,它将需要调整,但您明白了:
elseif ( is_single() && ! is_attachment() ) { if ( get_post_type() == 'product' ) { echo $prepend; if ( $terms = get_the_terms( $post->ID,'product_cat' ) ) { $referer = wp_get_referer(); foreach( $terms as $term){ $referer_slug = (strpos($referer,$term->slug)); if(!$referer_slug==false){ $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; 这里的主要工作是由wp_get_referer完成,它获取访问者导航到的产品的引用URL.其余代码检查URL中是否包含有效类别,并在痕迹中使用它. 有关更多信息,请参阅此处的Jonathon Js帖子http://www.cryoutcreations.eu/forums/t/wrong-breadcrumbs-displayed (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |