Displaying subcategories on category.php
-
Hi All,
I’m current building a template for a site that’ll be displaying products. The idea being each post will be a product and it’ll filed under certain categories. So at the minute I have a ‘Display’ category and inside that are ‘LCD’,’LED’,’TFT’ subcategories. Then within ‘LCD’ I have the subcategories ‘Alphanumeric’ and ‘Graphic’.When a user clicks on the Products button I take them to the category page where the entire tree is show, ie all the top level categories along with the subcategories. The permalink for this is ‘/index.php/category/products/’. That works fine, however when I click display it won’t display the subcategories, when clicking displays it takes the user to ‘/index.php/category/products/displays/’.
below is the coding for category.php for my template:
<?php get_header(); get_sidebar(); ?> <div id="content"> <?php $catinfo = get_the_category(); $catslug = $catinfo[0]->slug; $catid = $catinfo[0]->term_id; $catname = $catinfo[0]->name; ?> <div id="contentheader"><?php echo $catname ?></div><!--END #contentheader--> <p> <?php if($catslug == 'news'){ $myposts = get_posts('numberposts=3&offset=0&'.$catshow); foreach($myposts as $post): ?> <li><a href="<?php the_permalink(); ?>"><?php the_title();?></a></li> <?php endforeach; ?> <?php }else{ wp_list_categories('title_li=&hide_empty=0&child_of='.$catid); ?> <?php } ?> </p> <?php get_footer(); ?>Just to say that
if($catslug == 'news'){is used to see if we are looking at the news category and if so just display the posts not the subcategories.
My problem lies with$catinfo = get_the_category();This exists in ‘/index.php/products/’ but in ‘/index.php/products/display/’ it doesn’t exist meaning there is no child_of defined so all the categories are shown.
Thanks for any help.
Sephers.
The topic ‘Displaying subcategories on category.php’ is closed to new replies.