{"id":199080,"date":"2025-05-03T09:16:44","date_gmt":"2025-05-03T01:16:44","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199080\/"},"modified":"2025-05-03T09:16:44","modified_gmt":"2025-05-03T01:16:44","slug":"%e8%ae%be%e7%bd%aeecshop%e6%9c%80%e6%96%b0%e6%96%87%e7%ab%a0%e5%88%97%e8%a1%a8%e5%9c%a8%e6%89%80%e6%9c%89%e9%a1%b5%e9%9d%a2%e6%98%be%e7%a4%ba","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199080\/","title":{"rendered":"\u8bbe\u7f6eecshop\u6700\u65b0\u6587\u7ae0\u5217\u8868\u5728\u6240\u6709\u9875\u9762\u663e\u793a"},"content":{"rendered":"<p>\u8bbe\u7f6eecshop\u6700\u65b0\u6587\u7ae0\u5217\u8868\u5728\u6240\u6709\u9875\u9762\u663e\u793a   \u628a&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$smarty-&gt;assign(&#8216;new_articles&#8217;,&nbsp; &nbsp; index_get_new_articles());&nbsp; &nbsp;\/\/<br \/>\n<strong><font>\u6700\u65b0\u6587\u7ae0<\/font><\/strong><br \/>\n<br \/> \u52a0\u5230init.php \u4e2d\u7684&nbsp; &nbsp;&nbsp;&nbsp;$smarty-&gt;assign(&#8216;lang&#8217;, $_LANG);\u4e0b\u9762<br \/>\n<br \/> \u518d\u628afunction index_get_new_articles()<br \/>\n<br \/> {<br \/>\n<br \/> &nbsp; &nbsp; $sql = &#8216;SELECT a.article_id, a.title, ac.cat_name, a.add_time, a.file_url, a.open_type, ac.cat_id &#8216; .<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216; FROM &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;article&#8217;) . &#8216; AS a, &#8216; .<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;article_cat&#8217;) . &#8216; AS ac&#8217; .<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216; WHERE a.is_open = 1 AND a.cat_id = ac.cat_id AND ac.cat_type = 1&#8217; .<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216; ORDER BY a.article_type DESC, a.add_time DESC LIMIT &#8216; . $GLOBALS[&#8216;_CFG&#8217;][&#8216;article_number&#8217;];<br \/>\n<br \/> &nbsp; &nbsp; $res = $GLOBALS[&#8216;db&#8217;]-&gt;getAll($sql); <\/p>\n<p> &nbsp; &nbsp; $arr = array();<br \/>\n<br \/> &nbsp; &nbsp; foreach ($res AS $idx =&gt; $row)<br \/>\n<br \/> &nbsp; &nbsp; {<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arr[$idx][&#8216;id&#8217;]&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; = $row[&#8216;article_id&#8217;];<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arr[$idx][&#8216;title&#8217;]&nbsp; &nbsp;&nbsp; &nbsp; = $row[&#8216;title&#8217;];<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arr[$idx][&#8216;short_title&#8217;] = $GLOBALS[&#8216;_CFG&#8217;][&#8216;article_title_length&#8217;] &gt; 0 ?<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; sub_str($row[&#8216;title&#8217;], $GLOBALS[&#8216;_CFG&#8217;][&#8216;article_title_length&#8217;]) : $row[&#8216;title&#8217;];<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arr[$idx][&#8216;cat_name&#8217;]&nbsp; &nbsp; = $row[&#8216;cat_name&#8217;];<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arr[$idx][&#8216;add_time&#8217;]&nbsp; &nbsp; = local_date($GLOBALS[&#8216;_CFG&#8217;][&#8216;date_format&#8217;], $row[&#8216;add_time&#8217;]);<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arr[$idx][&#8216;url&#8217;]&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;= $row[&#8216;open_type&#8217;] != 1 ?<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 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 \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arr[$idx][&#8216;cat_url&#8217;]&nbsp; &nbsp;&nbsp;&nbsp;= build_uri(&#8216;article_cat&#8217;, array(&#8216;acid&#8217; =&gt; $row[&#8216;cat_id&#8217;]));<br \/>\n<br \/> &nbsp; &nbsp; } <\/p>\n<p> &nbsp; &nbsp; return $arr;<br \/>\n<br \/> }<br \/>\n<br \/> \u4e5f\u653e\u5230init.php \u91cc\u9762&nbsp; &nbsp; \u4fdd\u5b58&nbsp;&nbsp;\u4eb2\u7f13\u5b58&nbsp;&nbsp;OK <\/p>\n<p> \u8865\u5145\uff1a\u8fd8\u5f97\u628aindex.php\u4e2d\u7684 $smarty-&gt;assign(&#8216;new_articles&#8217;,&nbsp; &nbsp; index_get_new_articles());&nbsp; &nbsp; <\/p>\n<p> \u548c<br \/>\n<br \/> function index_get_new_articles()<br \/>\n<br \/> {<br \/>\n<br \/> &nbsp; &nbsp; $sql = &#8216;SELECT a.article_id, a.title, ac.cat_name, a.add_time, a.file_url, a.open_type, ac.cat_id &#8216; .<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216; FROM &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;article&#8217;) . &#8216; AS a, &#8216; .<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;article_cat&#8217;) . &#8216; AS ac&#8217; .<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216; WHERE a.is_open = 1 AND a.cat_id = ac.cat_id AND ac.cat_type = 1&#8217; .<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216; ORDER BY a.article_type DESC, a.add_time DESC LIMIT &#8216; . $GLOBALS[&#8216;_CFG&#8217;][&#8216;article_number&#8217;];<br \/>\n<br \/> &nbsp; &nbsp; $res = $GLOBALS[&#8216;db&#8217;]-&gt;getAll($sql); <\/p>\n<p> &nbsp; &nbsp; $arr = array();<br \/>\n<br \/> &nbsp; &nbsp; foreach ($res AS $idx =&gt; $row)<br \/>\n<br \/> &nbsp; &nbsp; {<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arr[$idx][&#8216;id&#8217;]&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; = $row[&#8216;article_id&#8217;];<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arr[$idx][&#8216;title&#8217;]&nbsp; &nbsp;&nbsp; &nbsp; = $row[&#8216;title&#8217;];<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arr[$idx][&#8216;short_title&#8217;] = $GLOBALS[&#8216;_CFG&#8217;][&#8216;article_title_length&#8217;] &gt; 0 ?<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; sub_str($row[&#8216;title&#8217;], $GLOBALS[&#8216;_CFG&#8217;][&#8216;article_title_length&#8217;]) : $row[&#8216;title&#8217;];<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arr[$idx][&#8216;cat_name&#8217;]&nbsp; &nbsp; = $row[&#8216;cat_name&#8217;];<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arr[$idx][&#8216;add_time&#8217;]&nbsp; &nbsp; = local_date($GLOBALS[&#8216;_CFG&#8217;][&#8216;date_format&#8217;], $row[&#8216;add_time&#8217;]);<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arr[$idx][&#8216;url&#8217;]&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;= $row[&#8216;open_type&#8217;] != 1 ?<br \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 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 \/>\n<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arr[$idx][&#8216;cat_url&#8217;]&nbsp; &nbsp;&nbsp;&nbsp;= build_uri(&#8216;article_cat&#8217;, array(&#8216;acid&#8217; =&gt; $row[&#8216;cat_id&#8217;]));<br \/>\n<br \/> &nbsp; &nbsp; } <\/p>\n<p> &nbsp; &nbsp; return $arr;<br \/>\n<br \/> }<br \/>\n<br \/> \u5220\u6389 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bbe\u7f6eecshop\u6700\u65b0\u6587\u7ae0\u5217\u8868\u5728\u6240&#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-199080","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199080","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=199080"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199080\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}