我在类别和子类别页面上添加类别列表(ul li)时遇到问题 . 我发现了一些类似的问题但发现只有一半的工作解决方案 . 这就是我设法做到的:我发现了代码的和平
function blue_categories()
{
$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' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$all_categories = get_categories( $args );
foreach ($all_categories as $cat) {
if($cat->category_parent == 0) {
$category_id = $cat->term_id;
echo '
<a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a>';
$args2 = array(
'taxonomy' => $taxonomy,
'child_of' => 0,
'parent' => $category_id,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$sub_cats = get_categories( $args2 );
if($sub_cats) {
foreach($sub_cats as $sub_category) {
echo $sub_category->name ;
}
}
}
}
}
这确实返回了类别和子类别的列表,但是我无法在wordpress,avada(主题)或woocommerce上找到任何文档,因为我必须调用此函数 . 我已将此函数添加到functions.php中,现在我不知道在哪里调用它 . “shop”,“categories-page”或“subcategories-page”在哪里创建?
所以我的一般问题是,如何在类别和子类别页面IN SIDEBAR上显示类别和子类别列表?除了编辑functions.php和模板文件之外,我1000%确定无法通过后台设置完成 .