2013-04-08 164 views

回答

11

您可以使用下列內容:

$args = array('taxonomy' => 'product_cat'); 
$terms = get_terms('product_cat', $args); 

if (count($terms) > 0) { 
    echo '<p class="my_term-archive">'; 
    foreach ($terms as $term) { 
     echo '<a href="/term-base/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a>';  
    } 
    echo '</p>'; 
} 
+0

我怎麼能得到圖像?我嘗試了'$ term-> image'&'$ term-> url' – 2014-10-15 00:29:34

+0

print_r($ terms)來查看輸出結果。如果該術語有一個圖像,它應該在陣列中 – danyo 2014-10-15 10:02:41

+0

哦,我明天整天都在尋找print_r函數!謝謝 – 2014-10-16 10:44:33

2

繼承人是我用來製造所有類別的列表由字母不包括空的信件和其他具有特色的類圖像!

所有你需要做的就是它的風格你想要的方式;)

<?php 

/* Define which category // to list child categories array('parent'=>42) 42 is category ID */ 
$designers = get_terms('product_cat', array('parent'=>42)); 

/* If categ not empty for each designer take first letter */ 
if (!empty($designers) && !is_wp_error($designers)){  
    $term_list = [];  
    foreach ($designers as $designer){ 
     $letter = strtoupper($designer->name[0]); 
     $designer_list[$letter][] = $designer; 
    } 
unset($designer); 


    foreach ($designer_list as $key=>$value) { 
     /* Wrap around each designer */ 
     echo '<div><span>' . $key . '</span><ul>'; 

     foreach ($value as $designer) { 
      // Set thumbnail 
      $thumbnail_id = get_woocommerce_term_meta($designer->term_id, 'thumbnail_id', true); 
      // get the image URL 
      $image = wp_get_attachment_url($thumbnail_id); 
      /* List designers */ 
      echo '<li><a href="' . get_term_link($designer) . '" title="' . sprintf(__('Products by %s', 'my_localization_domain'), $designer->name) . '">' . $designer->name . '<img src=" ' .$image.' "" alt="" /></a></li>'; 
     } 
     /* end Wrap around designer */ 
     echo '</ul></div>'; 
    }?> 
} 
相關問題