我试图通过我的WordPress主题中的函数从WooCommerce获取产品类别
function get_me_list_of($atts, $content = null)
{
$args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'product_cat' => $atts[0]);
$loop = new WP_Query( $args );
echo '<h1 class="upp">Style '.$atts[0].'</h1>';
echo "<ul class='mylisting'>";
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
echo '<li><a href="'.get_permalink().'">'.get_the_post_thumbnail($loop->post->ID, 'thumbnail').'</a></li>';
echo '<li><a href="'.get_permalink().'">'.$loop->post->post_title.'</a></li>';
echo '<li><a href="">'.get_categories().'</a></li>';
endwhile;
echo "</ul>";
wp_reset_query();
}
?>
Run Code Online (Sandbox Code Playgroud)
上面的代码返回了一些产品,但产品类别.
当我echo '<li><a href="">'.get_categories().'</a></li>';在上面的代码中包含它时,它返回一个数组.我该如何解决?
我如何更改此以从WooCommerce获取产品类别?
我正在为 Wordpress Woocommerce 网站设置模板,我想显示产品类别、子类别和产品列表以充当动态菜单。我希望它表现得像这样;
category 1
-subcategory 1
-product 1
-product 2
-subcategory 2
-product 3
category 2
-product 4
Run Code Online (Sandbox Code Playgroud)
我发现以下代码接近我想要的
<?php
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' …Run Code Online (Sandbox Code Playgroud)