If you have used DukaPress for any length of time, it is probable that you have come across something really annoying: products do not show up on your categories. Additionally, if you want to create pages which show your products using the grid view, you currently have to go through the painful process of creating separate pages for each category, then inserting the gird view shortcode into each page. This is less than ideal. Explaining this process to a client becomes ‘difficult’.
What if each category could just automatically show your products in the gird view without the need of you doing anything other than just…. putting your products in their respective categories? With help from Cookie Web, we’ve figured out a way to do just this.
How do you do this?
Basically, you need to create a custom category template for your theme and make it such that when your categories are viewed, the grid display shortcode is used to generate a page that shows your products nicely.
Every theme’s category templates will be different in terms of HTML and CSS but to achieve what we are describing you just need two pieces of code:
A. This code gets the category ID of the category being viewed
<?php $cat_id = get_query_var('cat'); $category = get_category($cat_id); ?>
B. This code then inserts the category ID into the grid display shortcode so that you can generate your product category pages:
<?php echo (do_shortcode('[dpsc_grid_display category="'.$cat_id.'" total="-1" column="3" per_page="12" type="duka" order="DESC"]')); ?>
C. Optionally, you can use this bit of code to print the category name somewhere on the page:
<?php echo $category->name ?>
See it in action
Our latest themes Mwendo, Sanaa, Begi and ShopKeeper already include this functionality. You can download them to see exactly how we implemented this. You can view their demos to see it in action – make sure you click on the categories!