質問: get_terms($taxonomyname, array('parent' => $pterm->term_id, 'orderby' => 'slug', 'hide_empty' => false)); foreach ($terms as $term) { echo '<li><a href="' . get_term_link( $term->name, $taxonomyname ) . '">' . $term->name . '</a></li>'; } } echo '</ul>'; ?>
回答: いくつかのカスタマイズをしました。これは親と子のカテゴリ画像を表示するのに役立ちます。必要に応じて、後でこのコードをカスタマイズできます。 $taxonomyname = "product_cat"; //this gets top layer terms only. this is done by setting parent to 0. $parent_terms = get_terms($taxonomyname, array('parent' => 0, 'orderby' => 'slug', 'hide_empty' => false)); echo '<ul>'; foreach ($parent_terms as $pterm) { //show parent categories echo '<li><a href="' . get_term_link($pterm->name, $taxonomyname) . '">' . $pterm->name . '</a></li>'; $thumbnail_id = get_woocommerce_term_meta($pterm->term_id, 'thumbnail_id', true); // get the image url for parent category $image = wp_get_attachment_url($thumbnail_id); // print the img html for parent category echo "<img src='{$image}' alt='' width='400' height='400' />"; //get the child terms $terms = get_terms($taxonomyname, array('parent' => $pterm->term_id, 'orderby' => 'slug', 'hide_empty' => false)); foreach ($terms as $term) { echo '<li><a href="' . get_term_link($term->name, $taxonomyname) . '">' . $term->name . '</a></li>'; $thumbnail_id = get_woocommerce_term_meta($pterm->term_id, 'thumbnail_id', true); // get the image url for child category $image = wp_get_attachment_url($thumbnail_id); // print the img html for child category echo "<img src='{$image}' alt='' width='400' height='400' />"; } } echo '</ul>'; それがあなたの要求を満たすかどうか私に知らせてください。