{"id":199220,"date":"2025-05-03T09:02:57","date_gmt":"2025-05-03T01:02:57","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199220\/"},"modified":"2025-05-03T09:02:57","modified_gmt":"2025-05-03T01:02:57","slug":"%e4%bf%ae%e6%94%b9ecshop%e5%88%a0%e9%99%a4%e8%a7%a3%e5%86%b3%e6%a0%87%e9%a2%98%e5%90%8e%e9%9d%a2%e7%9a%84%e7%9c%81%e7%95%a5%e5%8f%b7","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199220\/","title":{"rendered":"\u4fee\u6539ecshop\u5220\u9664\u89e3\u51b3\u6807\u9898\u540e\u9762\u7684\u7701\u7565\u53f7&#8230;"},"content":{"rendered":"<p>\u5728\u4e2d\u8bbe\u7f6e\u4e86{$goods.goods_name|truncate:10:&#8221;}\u6807\u9898\u540e\u9762\u8fd8\u662f\u4e00\u6837\u4f1a\u8ddf\u7740\u7701\u7565\u53f7 &#8230; \u8be5\u5982\u4f55\u89e3\u51b3\uff1a<\/p>\n<p>\u597d\u6a21\u677f\u63d0\u4f9b\u8be5\uff1a<\/p>\n<p> 1.\u9996\u5148ecshop\u7684\u6a21\u677f\u5f15\u64ce\u4e0d\u5b8c\u5168\u662fsmarty \u6240\u4ee5\u5728truncate\u51fd\u6570\u4e0a\u662f\u6709\u533a\u522b\u7684 &nbsp; \u627e\u5230 cls_template.php \u641c\u7d22truncate \u4f60\u4f1a\u53d1\u73b0\u4ee5\u4e0b\u4ee3\u7801 case &#8216;truncate&#8217;: $p = &#8216;sub_str(&#8216; . $p . &#8220;,$s[1])&#8221;; break; &nbsp; \u8fd9\u91cc\u7684 sub_str\u662fec\u7684\u4e00\u4e2a\u81ea\u5b9a\u4e49\u51fd\u6570\u5728 lib_base.php\u6587\u4ef6\u4e2d\u7684 \u4ee3\u7801\u5982\u4e0b\uff1a function sub_str($str, $length = 0, $append = true) { &nbsp; &nbsp; $str = trim($str); &nbsp; &nbsp; $strlength = strlen($str); &nbsp; &nbsp; if ($length == 0 || $length &gt;= $strlength) &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; return $str; &nbsp; &nbsp; } &nbsp; &nbsp; elseif ($length &lt; 0) &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; $length = $strlength + $length; &nbsp; &nbsp; &nbsp; &nbsp; if ($length &lt; 0) &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $length = $strlength; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; } &nbsp; &nbsp; if (function_exists(&#8216;mb_substr&#8217;)) &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; $newstr = mb_substr($str, 0, $length, EC_CHARSET); &nbsp; &nbsp; } &nbsp; &nbsp; elseif (function_exists(&#8216;iconv_substr&#8217;)) &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; $newstr = iconv_substr($str, 0, $length, EC_CHARSET); &nbsp; &nbsp; } &nbsp; &nbsp; else &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; \/\/$newstr = trim_right(substr($str, 0, $length)); &nbsp; &nbsp; &nbsp; &nbsp; $newstr = substr($str, 0, $length); &nbsp; &nbsp; } &nbsp; &nbsp; if ($append &amp;&amp; $str != $newstr) &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; $newstr .= &#8216;&#8230;&#8217;; &nbsp; &nbsp; } &nbsp; &nbsp; return $newstr; } \u5176\u4e2d \u4ed4\u7ec6\u770b \u8fd9\u4e2a\u51fd\u6570\u67093\u4e2a\u53c2\u6570 \u4f46\u662f\u5728\u6a21\u677f\u5f15\u64ce\u6587\u4ef6\u4e2d\u53ea\u4ee3\u4e862\u4e2a\u53c2\u6570 2. \u4ee5\u4e0b\u63d0\u4f9b\u4e24\u79cd\u65b9\u6cd5\u4fee\u6539\uff1a \u65b9\u6cd5\u4e00 \u627e\u5230 cls_template.php \u641c\u7d22truncate case &#8216;truncate&#8217;: $p = &#8216;sub_str(&#8216; . $p . &#8220;,$s[1],$s[2])&#8221;; break; &nbsp; \u7136\u540e\u5728\u4f60\u7684\u540e\u53f0\u6e05\u9664\u4e00\u4e0b\u7f13\u5b58 {$goods.goods_name|truncate:10:false} \u5c31\u53ea\u663e\u793a5\u4e2a\u5b57 \u4e5f\u4e0d\u4f1a\u51fa\u73b0&#8230; &nbsp; \u65b9\u6cd5\u4e8c&nbsp; \u76f4\u63a5\u7528\u4ee3\u7801\u5220\u9664\u9875\u9762\u663e\u793a\u4e2d\u7684\u7701\u7565\u53f7\uff0c\u627e\u5230lib_base.php\u4e2d &nbsp; &nbsp; if ($append &amp;&amp; $str != $newstr) &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; $newstr .= &#8216;&#8230;&#8217;; &nbsp; &nbsp; } &nbsp; \u8fd9\u6837{$goods.goods_style_name}\u4e5f\u4e0d\u4f1a\u663e\u793a &#8230;&nbsp; &nbsp; \u8fd9\u91cc\u597d\u6a21\u677f\u63a8\u8350\u5927\u5bb6\u4f7f\u7528\u7b2c\u4e00\u79cd\u65b9\u6cd5 &nbsp; <\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4e2d\u8bbe\u7f6e\u4e86{$goods.goo&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-199220","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=199220"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199220\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}