Show only Top Level subcategories one level deep on category pages
-
Hi guys,
I put some code on my categories.php page to make subcategory boxes appear, the only problem is it puts boxes for all the sub-sub categories too all mixed in, e.g.
https://www.apeshop.com.au/store-reviews-australia/
I only want the top level subcategories like “Fashion” to appear here, note it also lists Sunglasses, Lingerie, Shoes etc which are subcategories within fashion.
So how can I set it to go only one category deep? i.e. just show the top level subcategories?
This is my category.php file:
<?php
/**
* The template for displaying Category Archive pages.
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
*/
get_header(); ?>
<div id=”container”>
<div id=”content” role=”main”>
<style type=’text/css’>
.joe_sc {
display:inline;
}
.joe_sc a { display:block; float:left; text-align:center; color:#666; width:195px; height:100%; background: #E9FFEF; padding:3px; border: solid #D2F5DB 1px; margin:3px;}
.joe_sc a:hover { color:#000; background: #C9EECF; }
</style>
<?php
global $wp_query;
$subcategories = get_categories(“child_of={$wp_query->query_vars[‘cat’]}”);
if(count($subcategories) >= 1) {
foreach($subcategories as $sc) {
echo “<div class=’joe_sc joe_subcategory_{$sc->cat_ID}’>cat_ID) . “‘>” . $sc->name . “</div>”;
}
echo “<br clear=’all’ />”;
}
?>
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo ‘<div class=”archive-meta”>’ . $category_description . ‘</div>’;
/* Run the loop for the category page to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-category.php and that will be used instead.
*/
genesis_standard_loop();
?>
</div><!– #content –>
</div><!– #container –>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
- The topic ‘Show only Top Level subcategories one level deep on category pages’ is closed to new replies.