Posted By

zreedeecom on 12/23/10


Tagged

wordpress shortcode shopp


Versions (?)

Shopp product/category link shortcodes


 / 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)

  1. # !SHOPP SHORTCODES
  2. # PASTE THIS CODE IN THE functions.php FILE OF YOUR WP THEME
  3. function link_shopp_category($data) {
  4. $z = array("id" => "", "text" => "");
  5. extract(shortcode_atts($z, $data));
  6.  
  7. if($id) :
  8. shopp('catalog','category','id='.$id.'&load=true');
  9. if(shopp('category','id', 'return=true')) :
  10. $url = shopp('category','url','return=true');
  11. if($text=="") $text = shopp('category','name','return=true');
  12. shopp('catalog','category','reset=true');
  13. return "<a href='$url' title='$text'>$text</a>";
  14. else:
  15. return "<p>Error: Category not found.";
  16. endif;
  17. else :
  18. return "<p>There is an error with your syntax.</p>";
  19. endif;
  20. } # end menu_link
  21. add_shortcode('categorylink', 'link_shopp_category');
  22.  
  23. function link_shopp_product($data) {
  24. $z = array("id" => "", "text" => "");
  25. extract(shortcode_atts($z, $data));
  26.  
  27. if($id) :
  28. shopp('catalog','product','id='.$id.'&load=true');
  29. if(shopp('product','found')) :
  30. $url = shopp('product','url','return=true');
  31. if($text=="") $text = shopp('product','name','return=true');
  32. shopp('catalog','product','reset=true');
  33. return "<a href='$url' title='$text'>$text</a>";
  34. else :
  35. return "<p>Error: Product not found</p>";
  36. endif;
  37. else :
  38. return "<p>There is an error with your syntax.</p>";
  39. endif;
  40. } # end link_shopp_product
  41. add_shortcode('productlink', 'link_shopp_product');
  42.  
  43. # Use shortcodes in text widgets.
  44. add_filter('widget_text', 'do_shortcode');

Report this snippet  

You need to login to post a comment.