2013-04-08 132 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>'; 
    }?> 
} 
相关问题