Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I currently have a taxonomy called wpsc_product_category. Under that taxonomy I have several terms used as sub-categories, and finally each sub-category has a number of products. I'm trying to use wp_list_categories to show an ul starting from the parent category of the current product your are viewing. ¿Is this 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>

I thought of something like this, but I don't know how to retrieve $actualcategoryparentid.

Any ideas?

Thanks!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

this will work:

$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
    }
}
share|improve this answer
    
So I just have to add that and then replace $terms for $actualcategoryparentid? –  Rise Apr 26 '11 at 22:05
    
$term->parent within the foreach loop is what would be $actualcategoryparentid, but consider that if a product has more than one category with a parent, there will be more than one $term->parent –  Milo Apr 26 '11 at 22:08
    
Oh i got it! I have to do $child_of = $term->parent; –  Rise Apr 26 '11 at 22:09
    
Hmm I see. I hope I don't run into that problem too soon. Thanks for the helo Milo :) –  Rise Apr 26 '11 at 22:10
    
Milo, would it be possible to get the name of $term->parent too? So I can echo it before listing the products? –  Rise Apr 26 '11 at 22:51
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.