Hi
many thanks for your help.
when i display all the posts in category x, that i want to display a list of all the categories that all those posts use.
<?php
//cycle through posts and collect all category ids and tags ids used on these posts
$current_cat = get_query_var('cat');
$all_cats = array();
if (have_posts()) :
while (have_posts()) : the_post();
$cats = get_the_category();
if ($cats) {
foreach($cats as $cat) {
if ($cat->term_id != $current_cat) {
$all_cats[$cat->term_id] = $cat->term_id;
} //if ($cat->cat_ID
} //foreach
} // if ($cats)
endwhile;
endif;
rewind_posts();
// now display all cats and tags we collected
$types[0] = 'category';
foreach ($types as $type) {
if ($type == 'category') {
if ($all_cats) {
$term_ids = $all_cats; //implode(',', $all_cats);
//wp_list_categories('include='.$term_ids.'&title_li=Categories');
}
}
$taxonomy = $type;
$args = 'include='.implode(',', $term_ids);
$terms = get_terms( $taxonomy, $args );
if ($terms) {
foreach($terms as $term) {
if ($term->count > 0) {
echo '<b>' . '<a href="' . esc_attr(get_term_link($term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name. '/ </b> ';
}
}
}
}
?>