2017-06-15 126 views
0

目前即時通訊使用這種顯示代碼顯示產品分類Woocommerce/PHP

<?php 
    $args = array(
    'number' => 100, 
    'orderby' => 'title', 
    'order' => 'ASC', 
    'hide_empty' => false 
); 
$product_categories = get_terms('product_cat', $args); 
$count = count($product_categories); 
if ($count > 0) { 
foreach($product_categories as $product_category) { 
$cat_thumb_id = get_woocommerce_term_meta($product_category - > term_id,'thumbnail_id', true); 
$cat_thumb_url = wp_get_attachment_thumb_url($cat_thumb_id); 
$term_link = get_term_link($product_category, 'product_cat'); 
echo '<a href="'.$term_link.'"><img src="'.$cat_thumb_url.'"/></a>'; 
echo '<h4><a href="'.get_term_link($product_category).'">'.$product_category - > name.'</a></h4>'; 
} 
} 
?> 

,但我想發展這個代碼顯示基於產品標籤的產品類別是有辦法做到這個 ?

回答

0

玩過我的代碼後,我得到了我想要顯示的內容。 BTW

$海峽

代表你想顯示

<?php            
    $args = array(
    'number'  => 100, 
     'orderby' => 'title', 
     'order'  => 'ASC', 
     'hide_empty' => false); 
$product_categories = get_terms('product_cat', $args); 
$count = count($product_categories); 
if ($count > 0){ 
foreach ($product_categories as $product_category) { 
$args = array(
    'posts_per_page' => -1, 
    'tax_query' => array(
     'relation' => 'AND', 
     array(
      'taxonomy' => 'product_cat', 
      'field' => 'slug', 
      'terms' => 'white-wines' 
'terms' => $product_category - > slug 
), 
array(
'taxonomy' => 'product_tag', 
'field' => 'slug', 
// 'terms' => 'white-wines' 
'terms' => array($str) 
) 
), 
'post_type' => 'product', 
'orderby' => 'title,' 
); 
$products = new WP_Query($args); 
echo "<ul>"; 
while ($products - > have_posts()) { 
    $products - > the_post(); 

    $cat_thumb_id = get_woocommerce_term_meta($product_category - > term_id, 'thumbnail_id', true); 
    $cat_thumb_url = wp_get_attachment_thumb_url($cat_thumb_id); 
    $term_link = get_term_link($product_category, 'product_cat'); 

    echo '<a href="'.$term_link. 
    '"><img src="'.$cat_thumb_url. 
    '"/></a>'; 
    echo '<h4><a class="'.$product_category - > slug. 
    '" href="'.get_term_link($product_category). 
    '">'.$product_category - > name. 
    '</a></h4>'; 
    /* echo '<h1><a class="' . $product_category->slug . '" href="' . get_term_link($product_category) . '">' . $product_category->name . '</a></h1>';*/ 
    ? > 
    <!-- <li> 
    < a href = "<?php the_permalink(); ?>" > 
     <?php the_title(); ?> < /a> < /li>--> 
    <?php 
                  } 
                  echo "</ul>"; 
                 } 
                } 
               ?> 

如果你們有更好的想法,請張貼在這裏,讓我們可以互相幫助,謝謝你的產品標籤。