Shopp产品/类别链接快捷码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shopp产品/类别链接快捷码相关的知识,希望对你有一定的参考价值。

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');

以上是关于Shopp产品/类别链接快捷码的主要内容,如果未能解决你的问题,请参考以下文章

架构丰富的代码片段也应该用于产品列表吗?

用于 WordPress 的 PHP 片段,用于获取所有产品子类别

Woocommerce 继续购物按钮链接到最后一个产品类别页面

当产品未链接到类别时,SQL 按类别订购产品不起作用

更新Shopp上的价格

idea和Pycharm 等系列产品激活激活方法和激活码