Php 删除“;“商店”;来自吴哥商业区的面包屑
如何从woo commerce中的面包屑中删除商店文本?[主页-->商店-->粉色喜马拉雅盐] 我想根据我在WordPress网站的导航菜单设置面包屑。[主页-->产品-->盐-->粉色喜马拉雅盐] 我在主菜单中使用了一些页面、自定义链接、类别和产品 见截图 Bredcrumb-Php 删除“;“商店”;来自吴哥商业区的面包屑,php,wordpress,woocommerce,breadcrumbs,Php,Wordpress,Woocommerce,Breadcrumbs,如何从woo commerce中的面包屑中删除商店文本?[主页-->商店-->粉色喜马拉雅盐] 我想根据我在WordPress网站的导航菜单设置面包屑。[主页-->产品-->盐-->粉色喜马拉雅盐] 我在主菜单中使用了一些页面、自定义链接、类别和产品 见截图 Bredcrumb- 菜单- 您可以通过主题覆盖WooCommerce模板(阅读以下官方文档): 从plugins/woocommerce/templates/global/breadcrumb.php复制文件后 到:themes/y
菜单-
您可以通过主题覆盖WooCommerce模板(阅读以下官方文档): 从plugins/woocommerce/templates/global/breadcrumb.php复制文件后 到:
themes/yourtheme/woocommerce/global/breadcrumb.php
,您可以通过以下内容替换代码来更改代码:
<?php
/**
* Shop breadcrumb
*
* This template can be overridden by copying it to yourtheme/woocommerce/global/breadcrumb.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.3.0
* @see woocommerce_breadcrumb()
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! empty( $breadcrumb ) ) {
$breadcrumb0 = $breadcrumb[0];
$shop_txt = __( 'Shop', 'woocommerce' );
$products_txt = __( 'Products', 'woocommerce' );
$products_url = home_url( '/products/' );
$breadcrumb10 = array( $products_txt );
$breadcrumb11 = array( $products_txt, $products_url );
if(is_product() || is_shop() || is_product_category() || is_product_tag() ){
if( $breadcrumb[1][0] == $shop_txt ){
if( ! empty( $breadcrumb[1][1] ) )
$breadcrumb[1] = $breadcrumb11;
else
$breadcrumb[1] = $breadcrumb10;
} else {
unset($breadcrumb[0]);
array_unshift($breadcrumb, $breadcrumb0, $breadcrumb11);
}
}
echo $wrap_before;
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;
}
这可以用CSS解决,但除非你发布一个链接到你的商店,否则帮不上忙。
试着这样做:
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! empty( $breadcrumb ) ) {
echo $wrap_before;
foreach ( $breadcrumb as $key => $crumb ) {
if (trim(strip_tags($crumb[0])) == 'Shop') { continue; }
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;
}
将此行添加到自定义CSS
ul.breadcrumbs li:nth-of-type(2) {display:none}
如果它不工作,可能还需要!重要的
ul.breadcrumbs li:nth-of-type(2) {display:none!important}
我无法评论,这就是我必须回答的原因。请提供您网站的链接。我将使用精确的CSS更新我的答案。我通过对functions.php进行更改获得了答案
if(get_post_type()=='product')
{
echo sprintf($link,“#”,esc_html,“'Products,'thegem');
//echo sprintf($link,get_permalink(get_option('woocommerce\u shop\u page\u id',0)),esc_html_('Product','thegem');
$taxonomy='product_cat';
$terms=获取术语($post->ID,$taxonomy);
foreach(条款为$c){
$c->term\u id;
//回声';
如果($c->term_id=='36'){
echo$分隔符;
echo sprintf($link,get_permalink(106),esc_html__($c->name,'thegem'));
}
}
}
否则{
$slug=$post_type->rewrite;
printf($link、$home\u link.'/'.$slug['slug'].'/',$post\u type->labels->singular\u name);
}
受LoicTheAztec启发,这里是一个类似但略有不同需求的解决方案。假设您只想完全删除商店链接:
复制文件:plugins/woocommerce/templates/global/breadcrumb.php
致:themes/yourtheme/woocommerce/global/breadcrumb.php
在新文件中,查找该行
foreach ( $breadcrumb as $key => $crumb ) {
在这一行之后,添加这一行:
if (trim(strip_tags($crumb[0])) == 'Shop') { continue; }
最后的代码如下所示:
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! empty( $breadcrumb ) ) {
echo $wrap_before;
foreach ( $breadcrumb as $key => $crumb ) {
if (trim(strip_tags($crumb[0])) == 'Shop') { continue; }
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(!defined('ABSPATH')){
出口
}
如果(!空($breadcrumb)){
回音$wrap_;
foreach($key=>$crumb的面包屑){
if(trim(strip_tags($crumb[0])=='Shop'){continue;}
回音$before;
如果(!empty($crump[1])&&sizeof($breadcrumb)!==$key+1){
回声';
}否则{
echo esc_html($crumb[0]);
}
echo$after;
if(sizeof($breadcrumb)!=$key+1){
echo$分隔符;
}
}
回音$wrap_后;
}
您是否使用任何插件来实现这一点?据我所知,这是不可能的,我的朋友。你需要调用菜单而不是面包屑这是唯一的方法。@Pratikbhatt我只使用Woocommerce和Gem主题默认插件。如果(!is_shop())
在面包屑中,你可以添加条件script@HarshSigma我有可能是你的一个解决方案…如果你能给我一些反馈,请,谢谢。Thanx的答案。但我不只是想把商店搬走。我也想更换动态面包屑。