Php 在页面上显示特定产品属性的术语列表
在Woocommerce中,我试图创建一个简单的页面,其中包含我从product attributePhp 在页面上显示特定产品属性的术语列表,php,html,wordpress,woocommerce,taxonomy-terms,Php,Html,Wordpress,Woocommerce,Taxonomy Terms,在Woocommerce中,我试图创建一个简单的页面,其中包含我从product attributePau brand获得的所有品牌。但是我没有找到正确的方法 因此,此页面需要以列表的形式显示链接的品牌名称。这里有一个自定义快捷码函数,用于输出“pa_品牌”产品属性的链接术语名称列表。它可以使用Wordpress内容文本编辑器在任何页面或帖子中使用,也可以在php代码中使用: add_shortcode( 'product_attribute_list', 'shortcode_product_
Pau brand
获得的所有品牌。但是我没有找到正确的方法
因此,此页面需要以列表的形式显示链接的品牌名称。这里有一个自定义快捷码函数,用于输出“pa_品牌”产品属性的链接术语名称列表。它可以使用Wordpress内容文本编辑器在任何页面或帖子中使用,也可以在php代码中使用:
add_shortcode( 'product_attribute_list', 'shortcode_product_attribute_list' );
function shortcode_product_attribute_list( $atts ) {
// Shortcode Attributes
$atts = shortcode_atts( array(
'taxonomy' => 'pa_brand',
'orderby' => 'name',
'hide_empty' => false,
), $atts, 'product_attribute_list' );
$terms = get_terms( array(
'taxonomy' => $atts['taxonomy'],
'orderby' => $atts['orderby'],
'hide_empty' => $atts['hide_empty'],
) );
$html = '<ul class="' . $atts['taxonomy'] . ' brands">';
// Loop through the taxonomy terms
foreach( $terms as $term ){
$html .= '<li><a href="' . get_term_link( $term, $atts['taxonomy'] ) . '">' . $term->name . '</a></li>';
}
return $html . '</ul>'; // Return the output
}
2) 在php模板或代码上:
echo do_shortcode("[product_attribute_list]");
您只需将一些CSS规则添加到活动主题的styles.CSS文件中,即可获得所需的设计。这里有一个自定义快捷码函数,它将输出“pa_品牌”产品属性的链接术语名称列表。它可以使用Wordpress内容文本编辑器在任何页面或帖子中使用,也可以在php代码中使用:
add_shortcode( 'product_attribute_list', 'shortcode_product_attribute_list' );
function shortcode_product_attribute_list( $atts ) {
// Shortcode Attributes
$atts = shortcode_atts( array(
'taxonomy' => 'pa_brand',
'orderby' => 'name',
'hide_empty' => false,
), $atts, 'product_attribute_list' );
$terms = get_terms( array(
'taxonomy' => $atts['taxonomy'],
'orderby' => $atts['orderby'],
'hide_empty' => $atts['hide_empty'],
) );
$html = '<ul class="' . $atts['taxonomy'] . ' brands">';
// Loop through the taxonomy terms
foreach( $terms as $term ){
$html .= '<li><a href="' . get_term_link( $term, $atts['taxonomy'] ) . '">' . $term->name . '</a></li>';
}
return $html . '</ul>'; // Return the output
}
2) 在php模板或代码上:
echo do_shortcode("[product_attribute_list]");
您只需在活动主题的styles.CSS文件中添加一些CSS规则即可获得所需的设计。这太棒了。非常感谢:)这太棒了。非常感谢:)