Jigowatt

Shopp tutorial; only display top level categories

Posted by Jay on Friday, December 4th, 2009 at 12:42 pm

We love WordPress, and use it as a platform for many of our clients web sites. There are even eCommerce plugins available which we utilise for customers whose budget wont stretch to a full-blown Magento build. Our WordPress eCommerce plugin of choice is the fantastic Shopp.

We’re currently using Shopp on several sites successfully, however on one we’re currently building we needed the ability to display top-level categories, ignoring their children. The category display function displays all categories, regardless of arguments and while there seemed to be a function to display only top-level categories it didn’t work!

On further exploration it seemed that the function didn’t even exist so, we wrote our own. This does involve modifying a shopp core file but unfortunately there was no alternative in this instance. To add this function, add the following code to your core/model/Category.php file on line 664;

1
2
3
4
5
6
case "is-subcategory":
case "issubcategory":
if ($this->parent == 0):
return false;
endif;
break;

Then to display your top level categories on the front-end of your shop use the following code:

1
2
3
4
5
6
7
8
9
10
11
12
<ul>
<?php if(shopp('catalog','has-categories')): ?>
    <?php while(shopp('catalog','categories')): ?>
    <?php if(shopp('category','is-subcategory')) continue; ?>  
    <li>
    <a href="<?php shopp('category','slug'); ?>">            
    <?php shopp('category','name'); ?>
    </a>
    </li>    
    <?php endwhile; ?>
    <?php endif;?>
</ul>

This will format the top-level categories in an un-ordered list. Tested and used in Shopp 1.0.6. Enjoy!

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Design Float
  • email
  • StumbleUpon
  • Twitthis

Related posts:

Leave a Reply