我想将所有woocommerce类别的子类别都放在前端,如下所示:
<ul>
<li><a href="">Link</a>
<ul>
<li><a href="">Submenu link</a></li>
</ul>
</li>
</ul>
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' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
); …Run Code Online (Sandbox Code Playgroud) 我不知道如何添加else到foreach!
这是我的代码:
<?php $terms = get_the_terms( $post->ID , 'actor' );
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, 'actor' );
if( is_wp_error( $term_link ) )
continue;
echo '<a href="' . $term_link . '">' . $term->name . '</a>';
}
?>
Run Code Online (Sandbox Code Playgroud)