{"id":32810,"date":"2024-11-25T16:20:26","date_gmt":"2024-11-25T08:20:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32810\/"},"modified":"2024-11-25T16:20:26","modified_gmt":"2024-11-25T08:20:26","slug":"%e5%a6%82%e4%bd%95%e5%bc%80%e5%8f%91%e4%b8%80%e4%b8%aa%e8%87%aa%e5%8a%a8%e7%94%9f%e6%88%90%e5%bd%92%e6%a1%a3%e7%9a%84wordpress%e6%8f%92%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32810\/","title":{"rendered":"\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5f52\u6863\u7684WordPress\u63d2\u4ef6"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/465\/014\/169389668671780.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5f52\u6863\u7684WordPress\u63d2\u4ef6\u63d2\u56fe\" alt=\"\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5f52\u6863\u7684WordPress\u63d2\u4ef6\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5f52\u6863\u7684WordPress\u63d2\u4ef6<\/p>\n<p>\u5f15\u8a00\uff1a<br \/>WordPress\u662f\u4e00\u6b3e\u975e\u5e38\u6d41\u884c\u7684\u5f00\u6e90\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf\uff0c\u8bb8\u591a\u7f51\u7ad9\u90fd\u4f7f\u7528\u5b83\u6765\u521b\u5efa\u535a\u5ba2\u3002\u5f52\u6863\u662f\u535a\u5ba2\u4e2d\u4e00\u4e2a\u5e38\u89c1\u7684\u529f\u80fd\uff0c\u5b83\u53ef\u4ee5\u6309\u7167\u65e5\u671f\u5c06\u6587\u7ae0\u5206\u7c7b\u5c55\u793a\uff0c\u65b9\u4fbf\u8bfb\u8005\u67e5\u627e\u5386\u53f2\u6587\u7ae0\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5f52\u6863\u7684WordPress\u63d2\u4ef6\uff0c\u5e76\u63d0\u4f9b\u76f8\u5173\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u4e00\u3001\u63d2\u4ef6\u7684\u57fa\u672c\u7ed3\u6784<br \/>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5939\uff0c\u8be5\u6587\u4ef6\u5939\u5c06\u4f5c\u4e3a\u6211\u4eec\u63d2\u4ef6\u7684\u6839\u76ee\u5f55\u3002\u5728\u8fd9\u4e2a\u6587\u4ef6\u5939\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2aPHP\u6587\u4ef6\uff0c\u547d\u540d\u4e3aarchive-plugin.php\uff0c\u8fd9\u5c06\u662f\u6211\u4eec\u63d2\u4ef6\u7684\u4e3b\u6587\u4ef6\u3002<\/p>\n<p>\u5728archive-plugin.php\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u4f5c\u4e3a\u63d2\u4ef6\u7684\u57fa\u672c\u7ed3\u6784\uff1a<\/p>\n<pre>&lt;?php \/**\n * Plugin Name: Archive Plugin\n * Description: This plugin generates a monthly archive of your blog posts.\n * Version: 1.0\n * Author: Your Name\n *\/\n\n\/\/ Your plugin code here\n\n?&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5b9a\u4e49\u4e86\u63d2\u4ef6\u7684\u540d\u79f0\u3001\u63cf\u8ff0\u3001\u7248\u672c\u53f7\u548c\u4f5c\u8005\u4fe1\u606f\u3002\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u7f16\u5199\u63d2\u4ef6\u7684\u529f\u80fd\u4ee3\u7801\u4e86\u3002<\/p>\n<p>\u4e8c\u3001\u751f\u6210\u5f52\u6863\u7684\u529f\u80fd\u4ee3\u7801<br \/>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u5728archive-plugin.php\u6587\u4ef6\u4e2d\u6dfb\u52a0\u751f\u6210\u5f52\u6863\u7684\u529f\u80fd\u4ee3\u7801\u3002\u6211\u4eec\u5c06\u4f7f\u7528WordPress\u63d0\u4f9b\u7684\u94a9\u5b50\uff08hook\uff09\u51fd\u6570\u6765\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd\u3002<\/p>\n<pre>&lt;?php \/\/ Generate monthly archive\nfunction generate_monthly_archive() {\n    $years = wp_get_archives( array(\n        'type' =&gt; 'yearly',\n        'echo' =&amp;gt; 0\n    ) );\n\n    $output = '';\n\n    foreach ( $years as $year ) {\n        $output .= '&lt;h2&gt;' . $year . '&lt;\/h2&gt;';\n\n        $months = wp_get_archives( array(\n            'type' =&amp;gt; 'monthly',\n            'echo' =&amp;gt; 0,\n            'year' =&amp;gt; $year\n        ) );\n\n        $output .= '<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n  &#8216; . $months . &#8216;\n<\/ul>\n<p>&#8216;; } return $output; } \/\/ Add archive shortcode function archive_shortcode() { $archive = generate_monthly_archive(); return $archive; } add_shortcode( &#8216;archive&#8217;, &#8216;archive_shortcode&#8217; ); ?&gt; <\/p>\n<p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3agenerate_monthly_archive\u7684\u51fd\u6570\uff0c\u7528\u4e8e\u751f\u6210\u5f52\u6863\u7684HTML\u4ee3\u7801\u3002\u8be5\u51fd\u6570\u4f7f\u7528\u4e86wp_get_archives\u51fd\u6570\uff0c\u901a\u8fc7\u8bbe\u7f6etype\u53c2\u6570\u4e3ayearly\u548cmonthly\u6765\u5206\u522b\u751f\u6210\u5e74\u4efd\u548c\u6708\u4efd\u7684\u5f52\u6863\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3aarchive_shortcode\u7684\u51fd\u6570\uff0c\u7528\u4e8e\u5c06\u751f\u6210\u7684\u5f52\u6863\u4ee3\u7801\u63d2\u5165\u5230\u6587\u7ae0\u6216\u9875\u9762\u4e2d\u3002\u6211\u4eec\u4f7f\u7528\u4e86WordPress\u7684add_shortcode\u51fd\u6570\uff0c\u5c06shortcode\u4e3aarchive\u7684\u51fd\u6570archive_shortcode\u6dfb\u52a0\u5230WordPress\u7684\u77ed\u4ee3\u7801\u4e2d\u3002<\/p>\n<p>\u4e09\u3001\u63d2\u4ef6\u7684\u5b89\u88c5\u548c\u6fc0\u6d3b<br \/>\u5c06archive-plugin\u6587\u4ef6\u5939\u4e0a\u4f20\u5230WordPress\u7684\u63d2\u4ef6\u76ee\u5f55\uff08wp-content\/plugins\uff09\u4e2d\u3002\u7136\u540e\uff0c\u5728WordPress\u540e\u53f0\u7684\u63d2\u4ef6\u7ba1\u7406\u754c\u9762\u4e2d\u627e\u5230Archive Plugin\uff0c\u5e76\u70b9\u51fb\u6fc0\u6d3b\u6309\u94ae\uff0c\u5373\u53ef\u6210\u529f\u5b89\u88c5\u548c\u6fc0\u6d3b\u63d2\u4ef6\u3002<\/p>\n<p>\u56db\u3001\u5728\u6587\u7ae0\u4e2d\u4f7f\u7528\u5f52\u6863\u529f\u80fd<br \/>\u5728\u6587\u7ae0\u6216\u9875\u9762\u7684\u7f16\u8f91\u754c\u9762\uff0c\u53ef\u4ee5\u4f7f\u7528[archive]\u77ed\u4ee3\u7801\u6765\u63d2\u5165\u5f52\u6863\u529f\u80fd\u3002\u4fdd\u5b58\u5e76\u53d1\u5e03\u6587\u7ae0\u540e\uff0c\u524d\u53f0\u9875\u9762\u5c06\u4f1a\u81ea\u52a8\u663e\u793a\u6309\u7167\u65e5\u671f\u5f52\u6863\u7684\u6587\u7ae0\u5217\u8868\u3002<\/p>\n<p>\u603b\u7ed3\uff1a<br \/>\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5f52\u6863\u7684WordPress\u63d2\u4ef6\uff0c\u901a\u8fc7\u6dfb\u52a0\u76f8\u5173\u7684\u4ee3\u7801\u793a\u4f8b\uff0c\u8bf4\u660e\u4e86\u63d2\u4ef6\u7684\u57fa\u672c\u7ed3\u6784\u548c\u751f\u6210\u5f52\u6863\u7684\u529f\u80fd\u4ee3\u7801\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u5bf9\u63d2\u4ef6\u8fdb\u884c\u6269\u5c55\u548c\u5b9a\u5236\uff0c\u4f7f\u5176\u66f4\u52a0\u7b26\u5408\u81ea\u5df1\u7684\u535a\u5ba2\u98ce\u683c\u548c\u9700\u6c42\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u4f7f\u7528WordPress\u7684\u7528\u6237\u548c\u5f00\u53d1\u8005\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5f52\u6863\u7684WordPress\u63d2\u4ef6\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5f52\u6863\u7684WordPress\u63d2\u4ef6 \u5f15\u8a00\uff1aWordPress\u662f\u4e00\u6b3e\u975e\u5e38\u6d41\u884c\u7684\u5f00\u6e90\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf\uff0c\u8bb8\u591a\u7f51\u7ad9\u90fd\u4f7f\u7528\u5b83\u6765\u521b\u5efa\u535a\u5ba2\u3002\u5f52\u6863\u662f\u535a\u5ba2\u4e2d\u4e00\u4e2a\u5e38\u89c1\u7684\u529f\u80fd\uff0c\u5b83\u53ef\u4ee5\u6309\u7167\u65e5\u671f\u5c06\u6587\u7ae0\u5206\u7c7b\u5c55\u793a\uff0c\u65b9\u4fbf\u8bfb\u8005\u67e5\u627e\u5386\u53f2\u6587\u7ae0\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5f52\u6863\u7684WordPress\u63d2\u4ef6\uff0c\u5e76\u63d0\u4f9b\u76f8\u5173\u7684\u4ee3\u7801\u793a\u4f8b\u3002 \u4e00\u3001\u63d2\u4ef6\u7684\u57fa\u672c\u7ed3\u6784\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5939\uff0c\u8be5\u6587\u4ef6\u5939\u5c06\u4f5c\u4e3a\u6211\u4eec\u63d2\u4ef6\u7684\u6839\u76ee\u5f55\u3002\u5728\u8fd9\u4e2a\u6587\u4ef6\u5939\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2aPHP\u6587\u4ef6\uff0c\u547d\u540d\u4e3aarchive-plugin.php\uff0c\u8fd9\u5c06\u662f\u6211\u4eec\u63d2\u4ef6\u7684\u4e3b\u6587\u4ef6\u3002 \u5728archive-plugin.php\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u4f5c\u4e3a\u63d2\u4ef6\u7684\u57fa\u672c\u7ed3\u6784\uff1a &lt;?php \/** * Plugin Name: Archive Plugin * Description: This plugin generates a monthly archive of your blog posts. * Version: 1.0 * Author: Your Name *\/ \/\/ Your plugin code here ?&gt; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u6bb5\u4ee3\u7801\u5b9a\u4e49\u4e86\u63d2\u4ef6\u7684\u540d\u79f0\u3001\u63cf\u8ff0\u3001\u7248\u672c\u53f7\u548c\u4f5c\u8005\u4fe1\u606f\u3002\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u7f16\u5199\u63d2\u4ef6\u7684\u529f\u80fd\u4ee3\u7801\u4e86\u3002 \u4e8c\u3001\u751f\u6210\u5f52\u6863\u7684\u529f\u80fd\u4ee3\u7801\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u5728archive-plugin.php\u6587\u4ef6\u4e2d\u6dfb\u52a0\u751f\u6210\u5f52\u6863\u7684\u529f\u80fd\u4ee3\u7801\u3002\u6211\u4eec\u5c06\u4f7f\u7528WordPress\u63d0\u4f9b\u7684\u94a9\u5b50\uff08hook\uff09\u51fd\u6570\u6765\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd\u3002 &lt;?php \/\/ Generate monthly archive function generate_monthly_archive() { $years = wp_get_archives( array( &#8216;type&#8217; =&gt; &#8216;yearly&#8217;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-32810","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32810","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=32810"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32810\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}