WooCommerce - 使用永久链接和 html 显示特定父级的产品子类别

问题描述 投票:0回答:1

关于这个问题已经很好地解决了:

WooCommerce - 显示特定父级的产品子类别

我设法让它与此代码一起工作:

dd_action( 'woocommerce_single_product_summary', 'wpse124955_test', 99 );
function wpse124955_test() {
$taxonomy = 'product_cat';

$term_id = wp_get_post_terms(get_the_ID(), $taxonomy, array("fields" => "ids"));

$parent = '21';
$args = array(
    'fields' => 'ids',
    'child_of' => $parent
);
$branch_ids = get_terms( $taxonomy, $args );

$intersect_ids = array_intersect($term_id, $branch_ids);

foreach ( $intersect_ids as $tid ) {
    $tobj = get_term_by('id', $tid, 'product_cat');
    $name_arr[] = $tobj->name;
 }

$term_list = implode(', ', $name_arr);

echo $term_list;
}

使用此代码可以很好地打印子类别。

现在我想让子类别链接(到其自身)并用

括起来
<h1></h1>

这样我就可以用我的 css 来设置它的样式,但作为一个完全的 PHP 白痴,我不知道如何编辑上面的代码。

在互联网上搜索了几个小时,却没有得到简单的答案。这是最好的解决方案 - 只是需要一些调整!如果有人愿意帮助我将永远感激不已!谢谢!

php woocommerce categories
1个回答
0
投票
$name_arr[] = $tobj->name;

$name_arr[] = '<a href="'.get_permalink( $tid ).'"><h1>'.$tobj->name.'</h1></a>';

应该可以。

© www.soinside.com 2019 - 2024. All rights reserved.