/ Published in: PHP
Add two new shortcodes to create Shopp product/category links in an easy way.
**USAGE:**
The following shortcodes will now be available along your posts, pages and text widgets
[productlink id='' text=''] (Text is optional, if omitted the product name will appear)
[categorylink id='' text=''] (Text is optional, if omitted the category name will appear)
**USAGE:**
The following shortcodes will now be available along your posts, pages and text widgets
[productlink id='' text=''] (Text is optional, if omitted the product name will appear)
[categorylink id='' text=''] (Text is optional, if omitted the category name will appear)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# !SHOPP SHORTCODES # PASTE THIS CODE IN THE functions.php FILE OF YOUR WP THEME function link_shopp_category($data) { if($id) : shopp('catalog','category','id='.$id.'&load=true'); if(shopp('category','id', 'return=true')) : $url = shopp('category','url','return=true'); if($text=="") $text = shopp('category','name','return=true'); shopp('catalog','category','reset=true'); return "<a href='$url' title='$text'>$text</a>"; else: return "<p>Error: Category not found."; endif; else : return "<p>There is an error with your syntax.</p>"; endif; } # end menu_link add_shortcode('categorylink', 'link_shopp_category'); function link_shopp_product($data) { if($id) : shopp('catalog','product','id='.$id.'&load=true'); if(shopp('product','found')) : $url = shopp('product','url','return=true'); if($text=="") $text = shopp('product','name','return=true'); shopp('catalog','product','reset=true'); return "<a href='$url' title='$text'>$text</a>"; else : return "<p>Error: Product not found</p>"; endif; else : return "<p>There is an error with your syntax.</p>"; endif; } # end link_shopp_product add_shortcode('productlink', 'link_shopp_product'); # Use shortcodes in text widgets. add_filter('widget_text', 'do_shortcode');