Question

J'ai actuellement une taxonomie appelée wpsc_product_category. En vertu de cette taxonomie j'ai plusieurs termes utilisés comme sous-catégories, et enfin chaque sous-catégorie a un certain nombre de produits. Je suis en train d'utiliser wp_list_categories pour montrer une ul à partir de la catégorie parente du produit en cours de votre visionnée. ¿Est-ce possible?

<?php    

$taxonomy     = 'wpsc_product_category';
$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        = '';
$child_of     = $actualcategoryparentid

$args = array(
  'taxonomy'     => $taxonomy,
  'orderby'      => $orderby,
  'show_count'   => $show_count,
  'pad_counts'   => $pad_counts,
  'hierarchical' => $hierarchical,
  'title_li'     => $title
  'child_of'     => $child_of
);
?>

<ul>
<?php wp_list_categories( $args ); ?>
</ul>

je pensais à quelque chose comme ça, mais je ne sais pas comment récupérer $ actualcategoryparentid.

Toutes les idées?

Merci!

Était-ce utile?

La solution

ceci étant:

$terms = wp_get_object_terms( $post->ID, 'wpsc_product_category' );
foreach($terms as $term){
    if($term->parent != 0){
        // this category has a parent and its id is $term->parent
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à wordpress.stackexchange
scroll top