{"id":199062,"date":"2025-05-03T09:24:00","date_gmt":"2025-05-03T01:24:00","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199062\/"},"modified":"2025-05-03T09:24:00","modified_gmt":"2025-05-03T01:24:00","slug":"ecshop%e8%b0%83%e7%94%a8%e6%8c%87%e5%ae%9a%e5%88%86%e7%b1%bb%e7%9a%84%e6%96%87%e7%ab%a0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199062\/","title":{"rendered":"ecshop\u8c03\u7528\u6307\u5b9a\u5206\u7c7b\u7684\u6587\u7ae0"},"content":{"rendered":"<p>&nbsp;\u4e3e\u4f8b\u5982\u9996\u9875\u8c03\u7528\u65b9\u6cd5\uff1a<\/p>\n<p>1\u3001\u5148\u6253\u5f00index.php\u6587\u4ef6\u627e\u5230\u4ee5\u4e0b\u4ee3\u7801\uff1a<br \/> $smarty-&gt;assign(&#8216;new_articles&#8217;, index_get_new_articles()); \/\/ \u6700\u65b0\u6587\u7ae0<\/p>\n<p>\u5728\u5b83\u4e0b\u9762\u589e\u52a0\u4ee5\u4e0b\uff1a<br \/> \/\/\u8c03\u7528\u65b9\u6cd5<\/p>\n<p>$smarty-&gt;assign(&#8216;class_articles_4&#8217;, index_get_class_articles(4,6)); \/\/ \u5206\u7c7b\u8c03\u7528\u6587\u7ae0<br \/> \/\/\u8c03\u7528\u591a\u4e2a\u5c31\u4fee\u6539\u4f20\u8fdb\u53bb\u7684\u53c2\u6570,\u4ee5\u53ca\u6a21\u677f\u63a5\u6536\u7684\u53d8\u91cf,\u5176\u4e2d\u4e0a\u9762\u76844\u5c31\u662f\u6587\u7ae0\u5206\u7c7bID,\u5176\u4e2d6\u662f\u8c03\u7528\u6570\u91cf<br \/> $smarty-&gt;assign(&#8216;class_articles_5&#8217;, index_get_class_articles(5,6)); \/\/ \u5206\u7c7b\u8c03\u7528\u6587\u7ae0<br \/> $smarty-&gt;assign(&#8216;class_articles_6&#8217;, index_get_class_articles(6,6)); \/\/ \u5206\u7c7b\u8c03\u7528\u6587\u7ae0<br \/> $smarty-&gt;assign(&#8216;class_articles_7&#8217;, index_get_class_articles(7,6)); \/\/ \u5206\u7c7b\u8c03\u7528\u6587\u7ae0<br \/> $smarty-&gt;assign(&#8216;class_articles_8&#8217;, index_get_class_articles(8,6)); \/\/ \u5206\u7c7b\u8c03\u7528\u6587\u7ae0<\/p>\n<p> \/\/\u5728\u6700\u540e?&gt;\u8fd9\u4e2a\u4e4b\u524d\u589e\u52a0\u4ee5\u4e0b\u51fd\u6570<\/p>\n<p>\/**<br \/> * \u83b7\u5f97\u6307\u5b9a\u680f\u76ee\u6700\u65b0\u7684\u6587\u7ae0\u5217\u8868\u3002<br \/> *<br \/> * @access private<br \/> * @return array<br \/> *\/<br \/> function index_get_class_articles($cat_aid, $cat_num)<br \/> {<br \/> $sql = &#8220;SELECT article_id, title,open_type,cat_id,file_url FROM &#8221; .$GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;article&#8217;). &#8221; WHERE cat_id = &#8220;.$cat_aid.&#8221; and is_open = 1 LIMIT &#8221; . $cat_num;<br \/> $res = $GLOBALS[&#8216;db&#8217;]-&gt;getAll($sql);<br \/> $arr = array();<br \/> foreach ($res AS $idx =&gt; $row)<br \/> {<br \/> $arr[$idx][&#8216;id&#8217;] = $row[&#8216;article_id&#8217;];<br \/> $arr[$idx][&#8216;title&#8217;] = $row[&#8216;title&#8217;];<br \/> $arr[$idx][&#8216;short_title&#8217;] = $GLOBALS[&#8216;_CFG&#8217;][&#8216;article_title_length&#8217;] &gt; 0 ?<br \/> sub_str($row[&#8216;title&#8217;], $GLOBALS[&#8216;_CFG&#8217;][&#8216;article_title_length&#8217;]) : $row[&#8216;title&#8217;];<br \/> $arr[$idx][&#8216;cat_name&#8217;] = $row[&#8216;cat_name&#8217;];<br \/> $arr[$idx][&#8216;add_time&#8217;] = local_date($GLOBALS[&#8216;_CFG&#8217;][&#8216;date_format&#8217;], $row[&#8216;add_time&#8217;]);<br \/> $arr[$idx][&#8216;url&#8217;] = $row[&#8216;open_type&#8217;] != 1 ?<br \/> build_uri(&#8216;article&#8217;, array(&#8216;aid&#8217; =&gt; $row[&#8216;article_id&#8217;]), $row[&#8216;title&#8217;]) : trim($row[&#8216;file_url&#8217;]);<br \/> $arr[$idx][&#8216;cat_url&#8217;] = build_uri(&#8216;article_cat&#8217;, array(&#8216;acid&#8217; =&gt; $row[&#8216;cat_id&#8217;]));<br \/> }<br \/> return $arr;<br \/> }<\/p>\n<p>2\u3001\u7b2c\u4e8c\u6b65\u662f\u5728index.dwt\u6a21\u677f\u60f3\u8c03\u7528\u7684\u5730\u65b9\u589e\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff0c\uff08\u6ce8\uff1a\u4ee5\u4e0b\u8c03\u4e0a\u9762\u8bbe\u7f6e\u91cc\u7684\u5206\u7c7bID\u4e3a8\u7684\u6587\u7ae0\u5217\u8868)\uff1a<\/p>\n<p>&lt;!&#8211;{foreach from=$class_articles_8 item=article}&#8211;&gt;<br \/> &lt;li&gt;&lt;a href=&#8221;{$article.url}&#8221; title=&#8221;{$article.title|escape:html}&#8221;&gt;&lt;!&#8211;{$article.short_title|truncate:15:true}&#8211;&gt;&lt;\/a&gt;&lt;\/li&gt;<br \/> &lt;!&#8211;{\/foreach}&#8211;&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;\u4e3e\u4f8b\u5982\u9996\u9875\u8c03\u7528\u65b9\u6cd5\uff1a&#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-199062","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199062","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=199062"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199062\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}