によってサブカテゴリーを取得するか、woocomerceを呼び出したいですカテゴリを選択してこのコードを使用する
<div class="category">
<?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
);
$all_categories = get_categories($args);
foreach ($all_categories as $cat) {
if($cat->category_parent == 0) {
$category_id = $cat->term_id;
echo '<br /><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 ;
}
}
}
}
?>
</div>
Thコードのためのanks。それはサブカテゴリのリストを取得するのに効果的ですが、私は、日付のように、画像上に投稿の特定のサブカテゴリを表示したい。ここに私のフルコードは次のとおりです: 'もし(ヒストポストサムネイル($ post-> ID)) { $ image = wp_get_attachment_image_src(get_post_thumbnail_id($ post-> id)、 'シングルポストサムネイル'); エコー '' . get_the_date('M d, y') . ' '; } ' –
user3612498