0
商品のカスタムカテゴリをいくつか作成しました。サブカテゴリがあり、サブカテゴリにはさらにサブカテゴリがあります。今私は最初にメインのカテゴリを表示します。私はそこに表示する場合は、そのカテゴリとそのサブカテゴリに関連するすべてのサブカテゴリが表示されます。私はそれらを段階的に表示したいです。それは、ユーザーがメインカテゴリをクリックし、次に、そのサブカテゴリページに移動します。ユーザがそのサブカテゴリの1つをクリックするとサブカテゴリに行き、サブカテゴリがなければその製品を表示する。コードはこれですカテゴリとサブカテゴリ
$products = get_term_children($term_id[0], 'product-cat');
if(count($products) > 0){
$count = 0;
$sorted_products = array();
foreach ($products as $product) {
$sorted_products = get_term($product, 'product-cat');
$prod_meta = get_option("taxonomy_term_".$term->term_id);
//echo "<pre>"; print_r($sorted_products);
foreach ($sorted_products as $product) { ?>
<div class="col-md-3 col-sm-4 col-xs-12">
<a href="<?php echo $product['link']; ?>">
<a href="<?php echo $product['link']; ?>" class="hvr-grow">
<img class="center-block img-responsive" src="<?php echo $product['img'] ? $product['img'] : '/wp-content/themes/ruskin/images/dummy-product.jpg'; ?>" alt="<?php echo $product['name']; ?>">
<h3><a href="<?php echo $product['link']; ?>"><?php echo $product['name']; ?></a></h3>
else{
# Define the WP Query post arguments.
$args = array(
'post_status' => 'publish',
'post_type' => 'products',
'posts_per_page' => -1,
//'meta_query' => array('relation' => 'AND', array('key' => '_cus__featured', 'value' => '1', 'compare' => '='),),
'meta_key' => '_cus__sort_order',
//'meta_value' => 'meta_value',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'tax_query' => array(
array('taxonomy' => 'product-cat',
'field' => 'slug',
'terms' => $cats
)));
$loop = new WP_Query($args);
$total = $loop->found_posts;
$sliders='';
// Generatet the slider conteents
while ($loop->have_posts()) {
$loop->the_post();
$listingimg = get_post_custom_values('_cus__listing_img');
$listingimg = "/wp-content/themes/bodyo/images/no-slider-img.jpg";
$img = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'main_slide_img');
$img = "/wp-content/themes/bodyo/images/no-slider-img.jpg";
$sliders .= '<a href="'. get_the_permalink() .'" class="hvr-grow">';
$sliders .= '<img src="'.$listingimg.'" class="center-block img-responsive" alt="'. get_the_title() .'" />';
$sliders .= '</a>';
$sliders .= '</div>';
$sliders .= '<a href="'. get_the_permalink() .'">';
$sliders .= '<h3>'. get_the_title() .'</h3>';
$sliders .= '<p>'. get_the_excerpt() .'</p>';
$sliders .= '<a href="'. get_the_permalink() .'">read more</a>';
$counter++;
}
これは以前の並べ替え順序を上書きします。つまり、ダッシュボードからソート順に2〜3つのカテゴリを指定すると、最後のものが表示されます。最初の2つは上書きされます。
このステップでは、あなたが投稿したコードの最初の行である少し –
を詳しく説明できます。 –