脚本宝典收集整理的这篇文章主要介绍了php – 将Woocommerce父类添加到WP’body’类,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
每次进入子类别时,父类别不再在body类中.
也许像“PRoduct_parent_cat”这样的术语?试过这个并搜索他们的API但没有成功..
function woo_custom_taxonomy_in_body_class( $classes ){ $custom_terms = get_the_terms(0,'product_cat'); if ($custom_terms) { foreach ($custom_terms as $custom_term) { $classes[] = 'product_cat_' . $custom_term->slug; } } return $classes; } add_filter( 'body_class','woo_custom_taxonomy_in_body_class' );
function woo_custom_taxonomy_in_body_class( $classes ){ $custom_terms = get_the_terms(0,'product_cat'); if ($custom_terms) { foreach ($custom_terms as $custom_term) { // Check if the parent category exists: if( $custom_term->parent > 0 ) { // Get the parent product category: $parent = get_term( $custom_term->parent,'product_cat' ); // ApPEnd the parent class: if ( ! is_wp_error( $parent ) ) $classes[] = 'product_parent_cat_' . $parent->slug; } $classes[] = 'product_cat_' . $custom_term->slug; } } return $classes; } add_filter( 'body_class','woo_custom_taxonomy_in_body_class' );
将父产品类别slugs添加到body类.
以上是脚本宝典为你收集整理的php – 将Woocommerce父类添加到WP’body’类全部内容,希望文章能够帮你解决php – 将Woocommerce父类添加到WP’body’类所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。