Display only one level subcategory in wordpress
This code uses Taxonomy Images plugin to display images for categories. This code display subcategories of main category in parent category page (category.php
), But I want to display only one level of subcategory in the page for example
hardware (parent category)
monitor (first level subcategory of harware)
samsung (second level subcategory)
- lcd (third level subcategory )
When the user clicks on the hardware link, he should see only monitor subcategory link and in second time when he clicks on the monitor, he should see the samsung category link, and when he click on the samsung the subcategory LCD will displays. How should I change this code to do my word
My code:
?php
$cat_id = get_query_var('cat');
$catlist = get_categories('hide_empty=0child_of=' . $cat_id);
echo "ul";
foreach($catlist as $categories_item)
{
echo 'h1a href="' . get_category_link( $categories_item-term_id ) . '" title="' . sprintf( __( "View all products in %s" ), $categories_item-name ) . '" ' . '' . $categories_item-name.'/a /h1 ';
echo 'div class="categoryoverview clearfix"';
$terms = apply_filters( 'taxonomy-images-get-terms', '' );
if ( ! empty( $terms ) ) {
foreach( (array) $terms as $term ) {
if($term-term_id == $categories_item-term_id) {
print 'a href="' . esc_url( get_term_link( $term, $term-taxonomy ) ) . '"' . wp_get_attachment_image( $term-image_id, 'thumbnail' );
echo '/a';
}
}
echo 'p'. $categories_item-description; echo '/p';
}
echo '/div';
}
echo "/ul";
?
Topic taxonomy categories theme-development Wordpress
Category Web