Display sub-categories on category page

I'm attempting to have my sub-categories displayed on a category page, just as I did on the main shop page, but I haven't been able to find anything about this. Shouldn't sub-categories show up by default?

Main shop page: http://drrubinstein.server304.com/shop

Category page: http://drrubinstein.server304.com/shop/products/category/jan-marini-skin-research/

Sample sub-category: http://drrubinstein.server304.com/shop/products/category/jan-marini-skin-research-c-esta-line/

Thank you!

  • Kimberly
    • Champion of Loops

    bigshotnow

    Hi and Welcome to the WPMUdev community!

    The display of your store pages will depend on your theme.

    You can check out the ThemeingMarketpress.txt file that ships with the plugin or download the Framemarket Theme to get some basic template files to work from :slight_smile:

    Visiting your pages I can't see any immediate errors. I think its' just a matter of putting your touch of custom display :slight_smile:

    If you have any specific questions about how we can help you do that please feel free to attach a screenshot or a bit more info about what you are looking to do exactly.

    Best,

    Kimberly

    If the above action did not result in the resolution or common end to this ticket then please feel free to come back here for comment. Just be sure you mark "Not Resolved" to re-open or we might miss it! :slight_smile: Thanks!

  • aristath
    • Recruit

    When viewing a product category, you can display it's subcategories using this:

    <?php
    	$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    		wp_list_categories('taxonomy=product_category&depth=0&show_count=0&title_li=&child_of=' . $term->term_id);
    ?>

    You can put it in your template file and then all you need is just some css. :slight_smile:

  • bigshotnow
    • New Recruit

    I'm using the Thesis Theme and running into some issues. I'm able to use the code provided by aristath, but the Thesis header and footer are not showing up correctly. So, I'm attempting to target the category pages using Thesis hooks and build the custom template that way, but am not able to target the correct page.

    Shouldn't this work for all product categories?

    if ( is_tax('product_category') )

    Any suggestions? Thanks!

  • bigshotnow
    • New Recruit

    I was able to figure it out. I just added a hook to add the sub-categories (and images) to any 'product_category' taxonomy page. See below for reference.

    Thanks for your help!

    function list_shop_subcats() {
    	if (is_tax('product_category')) { 
    
    		$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    
    		$args=array(
    			'taxonomy' => 'product_category',
    			'title_li' => '',
    			'hide_empty' => 'false',
    			'child_of' => $term->term_id,
    			'hierarchical' => false
    		);
    
    		$categories=get_categories($args);
    		if (!empty($categories)) {
    			echo "<h3>Sub-Categories</h3>";
    			foreach($categories as $category) {
    
    				//This code uses the images selected in the Media menu (using Category Icons Lite plugin)
    				$query = "SELECT wp_posts.guid from wp_posts, wp_postmeta WHERE wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = '_wp_attachment_category' AND wp_postmeta.meta_value = " . $category->cat_ID;
    
    				global $wpdb;
    				//$wpdb->show_errors();
    				$myrows = $wpdb->get_results($query);
    				if($myrows){
    					foreach ($myrows as $image){
    						echo '<div class="mp-catbox"><a href="' . get_bloginfo('url') . '/shop/products/category/' . $category->slug . '"><img src="'. $image->guid . '" alt="'. $category->name .'" /></a>';
    					}
    				//$wpdb->print_error();
    				}else{
    					//default images
    				  echo '<div class="mp-catbox"><a href="' . get_bloginfo('url') . '/shop/products/category/' . $category->slug . '"><img src="' . get_bloginfo('template_directory') . '/images/placeholder.jpg" alt="" /></a>';
    				}
    			?>
    				<?php echo '<h4 class="mp-catbox-title"><a href="' . get_bloginfo('url') . '/shop/products/category/' . $category->slug . '">' . $category->name .'</a></h4>' ?>
    				<?php echo '<p class="mp-catbox-desc">'.$category->description . '</p></div>' ?>
    			<?php }
    
    			echo '<br style="clear:both" />';
    		}
    	}
    }
    add_action('thesis_hook_before_post','list_shop_subcats');

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.