{"id":33475,"date":"2024-11-25T11:24:18","date_gmt":"2024-11-25T03:24:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/33475\/"},"modified":"2024-11-25T11:24:18","modified_gmt":"2024-11-25T03:24:18","slug":"wordpress%e5%a6%82%e4%bd%95%e8%ae%be%e7%bd%ae%e6%96%87%e7%ab%a0%e6%a8%a1%e6%9d%bf","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/33475\/","title":{"rendered":"wordpress\u5982\u4f55\u8bbe\u7f6e\u6587\u7ae0\u6a21\u677f"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u5728 wordpress \u4e2d\u8bbe\u7f6e\u6587\u7ae0\u6a21\u677f\uff1f\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#8220;template-name.php&#8221; \u7684\u65b0\u6587\u4ef6\uff0c\u5176\u4e2d &#8220;template-name&#8221; \u662f\u60a8\u60f3\u8981\u7684\u6a21\u677f\u540d\u79f0\u3002\u6dfb\u52a0\u4ee3\u7801 &#8220;template name: my custom template&#8221;\uff0c\u5176\u4e2d &#8220;my custom template&#8221; \u662f\u60a8\u60f3\u8981\u7684\u6a21\u677f\u540d\u79f0\u3002\u81ea\u5b9a\u4e49\u6a21\u677f\u5185\u5bb9\uff0c\u6dfb\u52a0\u60a8\u60f3\u8981\u663e\u793a\u7684\u4ee3\u7801\u3002\u7f16\u8f91\u6587\u7ae0\uff0c\u5728 &#8220;\u5c5e\u6027&#8221; \u90e8\u5206\u5c06\u6a21\u677f\u5206\u914d\u7ed9\u6587\u7ae0\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202404\/16\/2024041601391747571.jpg\" class=\"aligncenter\" title=\"wordpress\u5982\u4f55\u8bbe\u7f6e\u6587\u7ae0\u6a21\u677f\u63d2\u56fe\" alt=\"wordpress\u5982\u4f55\u8bbe\u7f6e\u6587\u7ae0\u6a21\u677f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 WordPress \u4e2d\u8bbe\u7f6e\u6587\u7ae0\u6a21\u677f<\/strong><\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u521b\u5efa\u6587\u7ae0\u6a21\u677f\u6587\u4ef6<\/strong><\/p>\n<ol>\n<li>\u5728\u60a8\u7684\u4e3b\u9898\u6587\u4ef6\u5939\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u3002<\/li>\n<li>\u5c06\u6587\u4ef6\u547d\u540d\u4e3a &#8220;template-name.php&#8221;\uff0c\u5176\u4e2d &#8220;template-name&#8221; \u662f\u60a8\u60f3\u8981\u7684\u6a21\u677f\u540d\u79f0\u3002\u4f8b\u5982\uff1a &#8220;template-blog.php&#8221;\u3002<\/li>\n<\/ol>\n<p><strong>\u6b65\u9aa4 2\uff1a\u6dfb\u52a0\u6a21\u677f\u4ee3\u7801<\/strong><\/p>\n<ol>\n<li>\u5728\u60a8\u521b\u5efa\u7684\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre>&lt;?php\n\/*\nTemplate Name: My Custom Template\n*\/\n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u66ff\u6362 &#8220;My Custom Template&#8221; \u4e3a\u60a8\u60f3\u8981\u7684\u6a21\u677f\u540d\u79f0\u3002<\/p>\n<p><strong>\u6b65\u9aa4 3\uff1a\u81ea\u5b9a\u4e49\u6a21\u677f<\/strong><\/p>\n<ol>\n<li>\u5728 \u548c \u4e4b\u95f4\u6dfb\u52a0\u60a8\u60f3\u8981\u5728\u6a21\u677f\u4e2d\u663e\u793a\u7684\u4ee3\u7801\u3002<\/li>\n<li>\u81ea\u5b9a\u4e49\u5185\u5bb9\u3001\u8fb9\u680f\u3001\u9875\u7709\u548c\u9875\u811a\uff0c\u4ee5\u521b\u5efa\u60a8\u9700\u8981\u7684\u72ec\u7279\u5e03\u5c40\u3002<\/li>\n<\/ol>\n<p><strong>\u6b65\u9aa4 4\uff1a\u5c06\u6a21\u677f\u5206\u914d\u7ed9\u6587\u7ae0<\/strong><\/p>\n<ol>\n<li>\u7f16\u8f91\u60a8\u8981\u4f7f\u7528\u8be5\u6a21\u677f\u7684\u6587\u7ae0\u3002<\/li>\n<li>\u5728\u4fa7\u8fb9\u680f\u7684 &#8220;\u5c5e\u6027&#8221; \u90e8\u5206\uff0c\u9009\u62e9\u60a8\u521b\u5efa\u7684\u6a21\u677f\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u8981\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#8220;Blog \u6a21\u677f&#8221; \u7684\u6a21\u677f\uff0c\u8bf7\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#8220;template-blog.php&#8221; \u7684\u6587\u4ef6\u3002<\/li>\n<li>\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre>&lt;?php\n\/*\nTemplate Name: Blog Template\n*\/\n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u5728 \u548c \u4e4b\u95f4\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u4ee5\u663e\u793a\u6587\u7ae0\u5217\u8868\uff1a<\/li>\n<\/ol>\n<pre>&lt;?php\n$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;\n$args = array(\n    'post_type' =&gt; 'post',\n    'paged' =&gt; $paged,\n);\n$query = new WP_Query( $args );\nwhile ( $query-&gt;have_posts() ) : $query-&gt;the_post();\n    get_template_part( 'template-parts\/content', get_post_format() );\nendwhile;\nwp_reset_postdata();\n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0c\u60a8\u5df2\u7ecf\u4e3a WordPress \u6587\u7ae0\u521b\u5efa\u4e86\u4e00\u4e2a\u81ea\u5b9a\u4e49\u6a21\u677f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u8bbe\u7f6e\u6587\u7ae0\u6a21\u677f\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\u5728 wordpress \u4e2d\u8bbe\u7f6e\u6587\u7ae0\u6a21\u677f\uff1f\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#8220;template-name.php&#8221; \u7684\u65b0\u6587\u4ef6\uff0c\u5176\u4e2d &#8220;template-name&#8221; \u662f\u60a8\u60f3\u8981\u7684\u6a21\u677f\u540d\u79f0\u3002\u6dfb\u52a0\u4ee3\u7801 &#8220;template name: my custom template&#8221;\uff0c\u5176\u4e2d &#8220;my custom template&#8221; \u662f\u60a8\u60f3\u8981\u7684\u6a21\u677f\u540d\u79f0\u3002\u81ea\u5b9a\u4e49\u6a21\u677f\u5185\u5bb9\uff0c\u6dfb\u52a0\u60a8\u60f3\u8981\u663e\u793a\u7684\u4ee3\u7801\u3002\u7f16\u8f91\u6587\u7ae0\uff0c\u5728 &#8220;\u5c5e\u6027&#8221; \u90e8\u5206\u5c06\u6a21\u677f\u5206\u914d\u7ed9\u6587\u7ae0\u3002 \u5982\u4f55\u5728 WordPress \u4e2d\u8bbe\u7f6e\u6587\u7ae0\u6a21\u677f \u6b65\u9aa4 1\uff1a\u521b\u5efa\u6587\u7ae0\u6a21\u677f\u6587\u4ef6 \u5728\u60a8\u7684\u4e3b\u9898\u6587\u4ef6\u5939\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u3002 \u5c06\u6587\u4ef6\u547d\u540d\u4e3a &#8220;template-name.php&#8221;\uff0c\u5176\u4e2d &#8220;template-name&#8221; \u662f\u60a8\u60f3\u8981\u7684\u6a21\u677f\u540d\u79f0\u3002\u4f8b\u5982\uff1a &#8220;template-blog.php&#8221;\u3002 \u6b65\u9aa4 2\uff1a\u6dfb\u52a0\u6a21\u677f\u4ee3\u7801 \u5728\u60a8\u521b\u5efa\u7684\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a &lt;?php \/* Template Name: My Custom Template *\/ ?&gt; \u767b\u5f55\u540e\u590d\u5236 \u66ff\u6362 &#8220;My Custom Template&#8221; \u4e3a\u60a8\u60f3\u8981\u7684\u6a21\u677f\u540d\u79f0\u3002 \u6b65\u9aa4 3\uff1a\u81ea\u5b9a\u4e49\u6a21\u677f \u5728 \u548c \u4e4b\u95f4\u6dfb\u52a0\u60a8\u60f3\u8981\u5728\u6a21\u677f\u4e2d\u663e\u793a\u7684\u4ee3\u7801\u3002 \u81ea\u5b9a\u4e49\u5185\u5bb9\u3001\u8fb9\u680f\u3001\u9875\u7709\u548c\u9875\u811a\uff0c\u4ee5\u521b\u5efa\u60a8\u9700\u8981\u7684\u72ec\u7279\u5e03\u5c40\u3002 \u6b65\u9aa4 4\uff1a\u5c06\u6a21\u677f\u5206\u914d\u7ed9\u6587\u7ae0 [&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-33475","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/33475","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=33475"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/33475\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=33475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=33475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=33475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}