{"id":60053,"date":"2025-04-24T11:20:01","date_gmt":"2025-04-24T03:20:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/60053\/"},"modified":"2025-04-24T11:20:01","modified_gmt":"2025-04-24T03:20:01","slug":"%e8%ae%a9ecshop%e5%88%86%e7%b1%bb%e6%a0%91%e6%98%be%e7%a4%ba%e5%85%b7%e4%bd%93%e5%88%86%e7%b1%bb%e4%ba%a7%e5%93%81%e6%95%b0%e9%87%8f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/60053\/","title":{"rendered":"\u8ba9ecshop\u5206\u7c7b\u6811\u663e\u793a\u5177\u4f53\u5206\u7c7b\u4ea7\u54c1\u6570\u91cf"},"content":{"rendered":"<p>&nbsp;\u6211\u4eec\u60f3\u8ba9ecshop\u7684\u5206\u7c7b\u6570\u540e\u9762\u663e\u793a\u8be5\u5206\u7c7b\u4ea7\u54c1\u5177\u4f53\u6570\u91cf\uff0c\u8fd9\u91cc\u597d\u6a21\u677f\u63d0\u4f9b\u5177\u4f53\u529e\u6cd5\uff1a<\/p>\n<p><span style=\"border-collapse: collapse;font-family: Verdana, Helvetica, Arial, sans-serif\">\u4fee\u6539includes\/lib_goods.php<\/p>\n<p> $sql = &#8216;SELECT cat_id,cat_name ,parent_id,is_show &#8216; .<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &#8216;FROM &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;category&#8217;) .<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &#8220;WHERE parent_id = &#8216;$parent_id&#8217; AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC&#8221;;<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$res = $GLOBALS[&#8216;db&#8217;]-&gt;getAll($sql);<br \/> \u7684\u4e0b\u9762\u589e\u52a0<\/p>\n<p> <font style=\"line-height: normal\">$sql = &#8220;SELECT cat_id, COUNT(*) AS goods_num &#8221; .<br \/> &nbsp; &nbsp;&#8221; FROM &#8221; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;goods&#8217;) . &#8221; AS g &#8221; .<br \/> &nbsp; &nbsp;&#8221; GROUP BY cat_id&#8221;;<\/font><br \/> <font style=\"line-height: normal\">&nbsp; &nbsp; $res2 = $GLOBALS[&#8216;db&#8217;]-&gt;getAll($sql);<br \/> &nbsp; &nbsp; $newres = array();<br \/> &nbsp; &nbsp; foreach($res2 AS $row)<br \/> &nbsp; &nbsp; {<br \/> &nbsp; &nbsp;&nbsp;&nbsp;$newres[$row[&#8216;cat_id&#8217;]] = $row[&#8216;goods_num&#8217;];<br \/> &nbsp; &nbsp; }<\/font><\/p>\n<p> <font style=\"line-height: normal\">2.cat_arr[$row[&#8216;cat_id&#8217;]][&#8216;id&#8217;]&nbsp; &nbsp;= $row[&#8216;cat_id&#8217;];<\/font><br \/> <font style=\"line-height: normal\">\u4e0b\u9762\u589e\u52a0<\/font><br \/> <font style=\"line-height: normal\">$cat_arr[$row[&#8216;cat_id&#8217;]][&#8216;num&#8217;] = !empty($newres[$row[&#8216;cat_id&#8217;]]) ? $newres[$row[&#8216;cat_id&#8217;]] : 0;<\/font><\/p>\n<p> <font style=\"line-height: normal\"><font style=\"line-height: normal\"><strong>2.\u4fee\u6539category_tree.lib\u5e93\uff0c\u5199\u5165num\u53d8\u91cf\u3002<\/strong><\/font><\/font><br \/> <font style=\"line-height: normal\"><br \/> <\/font><br \/> <font style=\"line-height: normal\"><font style=\"line-height: normal\">&lt;dt&gt;&lt;a href=&#8221;{$cat.url}&#8221;&gt;{$cat.name|escape:html}&lt;\/a&gt;<font style=\"line-height: normal\">({$cat.num})<\/font>&lt;\/dt&gt;<\/font><\/font><\/span><\/p>\n<p>\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" style=\"cursor:pointer\" src=\"https:\/\/www.ldhost.cn\/helphmb\/uploads\/allimg\/110707\/1_110707201749_1_lit.jpg\" class=\"aligncenter\" title=\"\u8ba9ecshop\u5206\u7c7b\u6811\u663e\u793a\u5177\u4f53\u5206\u7c7b\u4ea7\u54c1\u6570\u91cf\u63d2\u56fe\" alt=\"\u8ba9ecshop\u5206\u7c7b\u6811\u663e\u793a\u5177\u4f53\u5206\u7c7b\u4ea7\u54c1\u6570\u91cf\u63d2\u56fe\" \/><br \/>\n<br \/> ecshop\u5206\u7c7b\u6811\u663e\u793a\u5177\u4f53\u5206\u7c7b\u5546\u54c1\u6570\u91cf <\/p>\n<p>\u6b64\u7531\u597d\u6a21\u677f\u63d0\u4f9b\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;\u6211\u4eec\u60f3\u8ba9ecshop\u7684\u5206\u7c7b\u6570\u540e\u9762\u663e\u793a\u8be5\u5206\u7c7b\u4ea7\u54c1\u5177\u4f53\u6570\u91cf\uff0c\u8fd9\u91cc\u597d\u6a21\u677f\u63d0\u4f9b\u5177\u4f53\u529e\u6cd5\uff1a \u4fee\u6539includes\/lib_goods.php $sql = &#8216;SELECT cat_id,cat_name ,parent_id,is_show &#8216; . &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &#8216;FROM &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;category&#8217;) . &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &#8220;WHERE parent_id = &#8216;$parent_id&#8217; AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC&#8221;; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$res = $GLOBALS[&#8216;db&#8217;]-&gt;getAll($sql); \u7684\u4e0b\u9762\u589e\u52a0 $sql = &#8220;SELECT cat_id, COUNT(*) AS goods_num &#8221; . [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-60053","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/60053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=60053"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/60053\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=60053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=60053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=60053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}