Problem: Today I needed to add some code to a Shopp (ver 1.1.9) product.php template so that related products (that have same ‘Tag’) would show up at the bottom. The ‘Related Products‘ template tag was not behaving as I expected it to.. i.e. it was stopping the product page rendering anything at all.
Fix: After chatting to some of the support Mods on IRC (thanks @TheWebBaker and @umargl0bal, it seemed I might need to reset the category query (category docs- see ‘reset’ option) after calling ‘Related Products‘, but this didn’t work. I turns out (sort of obviously in hindsight) that the product query needed to be reset instead (product docs – see ‘reset’ option). Here’s some working code inside product.php:
<?php shopp('catalog', 'related-products'); ?>
<?php shopp('catalog', 'product', 'reset=1'); ?>
That code can be placed anywhere in the product template but it makes sense to put it at the beginning or end of the product listing.
Tips:
- If you want to show random products you can use the ‘order=random’ option in the ‘related-products’ tab (see below for an example).
- If you want to limit the number of related products shown, use the ‘show=#’ option also (see below for example).
<?php shopp('catalog', 'related-products','show=3&order=random'); ?>
- The related items will be rendered using the category.php template. If you want to create a custom template JUST for related items (you really do) then copy category.php as category-related.php and customise that. This new template file will be called to render the related products.
Leave a Reply