{"id":4707,"date":"2025-10-20T09:09:31","date_gmt":"2025-10-20T01:09:31","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/?p=4707"},"modified":"2025-10-20T09:09:31","modified_gmt":"2025-10-20T01:09:31","slug":"wordpress%e8%87%aa%e5%ae%9a%e4%b9%89%e5%8a%9f%e8%83%bd%e6%8f%92%e4%bb%b6%e4%bc%98%e5%85%88%e7%b1%bb%e5%9e%8b%e6%8e%a8%e8%8d%90","status":"publish","type":"post","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/post\/4707.html","title":{"rendered":"WordPress\u81ea\u5b9a\u4e49\u529f\u80fd\u63d2\u4ef6\u4f18\u5148\u7c7b\u578b\u63a8\u8350"},"content":{"rendered":"<p>\u5728WordPress\u4e2d\uff0c\u5c06\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u3001\u81ea\u5b9a\u4e49\u5206\u7c7b\u6cd5\u548c\u5143\u6570\u636e\u5b57\u6bb5\u653e\u5728<strong>\u63d2\u4ef6\u4e2d<\/strong>\u901a\u5e38\u662f<strong>\u66f4\u5408\u9002\u7684\u9009\u62e9<\/strong>\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u5206\u6790\u548c\u5efa\u8bae\uff1a<\/p><h2 class=\"wp-block-heading\">\ud83c\udfaf \u6838\u5fc3\u7ed3\u8bba\uff1a\u4f18\u5148\u9009\u62e9\u63d2\u4ef6<\/h2><h3 class=\"wp-block-heading\">\u2705 \u63d2\u4ef6\u65b9\u5f0f\u7684\u4f18\u52bf<\/h3><ol class=\"wp-block-list\">\n<li><strong>\u6570\u636e\u6301\u4e45\u6027<\/strong><\/li>\n<\/ol><ul class=\"wp-block-list\">\n<li>\u5207\u6362\u4e3b\u9898\u65f6\u529f\u80fd\u4e0d\u4f1a\u4e22\u5931<\/li>\n\n\n\n<li>\u81ea\u5b9a\u4e49\u5185\u5bb9\u548c\u8bbe\u7f6e\u4fdd\u6301\u5b8c\u6574<\/li>\n\n\n\n<li>\u907f\u514d\u6570\u636e&#8221;\u5b64\u513f\u5316&#8221;<\/li>\n<\/ul><ol class=\"wp-block-list\">\n<li><strong>\u6a21\u5757\u5316\u548c\u53ef\u91cd\u7528\u6027<\/strong><\/li>\n<\/ol><ul class=\"wp-block-list\">\n<li>\u53ef\u5728\u591a\u4e2a\u7f51\u7ad9\u95f4\u590d\u7528<\/li>\n\n\n\n<li>\u72ec\u7acb\u4e8e\u4e3b\u9898\u8bbe\u8ba1\u903b\u8f91<\/li>\n\n\n\n<li>\u4fbf\u4e8e\u7248\u672c\u63a7\u5236\u548c\u66f4\u65b0<\/li>\n<\/ul><ol class=\"wp-block-list\">\n<li><strong>\u66f4\u597d\u7684\u4ee3\u7801\u7ec4\u7ec7<\/strong><\/li>\n<\/ol><ul class=\"wp-block-list\">\n<li>\u529f\u80fd\u76f8\u5173\u7684\u4ee3\u7801\u96c6\u4e2d\u7ba1\u7406<\/li>\n\n\n\n<li>\u9075\u5faa\u5355\u4e00\u804c\u8d23\u539f\u5219<\/li>\n<\/ul><h2 class=\"wp-block-heading\">\ud83d\udcc1 \u4ee3\u7801\u7ed3\u6784\u793a\u4f8b<\/h2><h3 class=\"wp-block-heading\">\u63d2\u4ef6\u76ee\u5f55\u7ed3\u6784<\/h3><pre class=\"wp-block-code\"><code>my-custom-content\/\n\u251c\u2500\u2500 my-custom-content.php\n\u251c\u2500\u2500 includes\/\n\u2502   \u251c\u2500\u2500 post-types.php\n\u2502   \u251c\u2500\u2500 taxonomies.php\n\u2502   \u2514\u2500\u2500 meta-fields.php\n\u2514\u2500\u2500 assets\/\n    \u251c\u2500\u2500 css\/\n    \u2514\u2500\u2500 js\/<\/code><\/pre><h3 class=\"wp-block-heading\">\u4e3b\u63d2\u4ef6\u6587\u4ef6<\/h3><pre class=\"wp-block-code\"><code>&lt;?php\n\/**\n * Plugin Name: My Custom Content\n * Description: \u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u3001\u5206\u7c7b\u6cd5\u548c\u5143\u5b57\u6bb5\n *\/\n\n\/\/ \u9632\u6b62\u76f4\u63a5\u8bbf\u95ee\nif (!defined('ABSPATH')) {\n    exit;\n}\n\n\/\/ \u5b9a\u4e49\u63d2\u4ef6\u5e38\u91cf\ndefine('MCC_PLUGIN_URL', plugin_dir_url(__FILE__));\ndefine('MCC_PLUGIN_PATH', plugin_dir_path(__FILE__));\n\n\/\/ \u5305\u542b\u529f\u80fd\u6587\u4ef6\nrequire_once MCC_PLUGIN_PATH . 'includes\/post-types.php';\nrequire_once MCC_PLUGIN_PATH . 'includes\/taxonomies.php';\nrequire_once MCC_PLUGIN_PATH . 'includes\/meta-fields.php';\n\n\/\/ \u6fc0\u6d3b\/\u505c\u7528\u94a9\u5b50\nregister_activation_hook(__FILE__, 'mcc_activate');\nregister_deactivation_hook(__FILE__, 'mcc_deactivate');\n\nfunction mcc_activate() {\n    \/\/ \u5237\u65b0\u91cd\u5199\u89c4\u5219\n    flush_rewrite_rules();\n}\n\nfunction mcc_deactivate() {\n    \/\/ \u6e05\u7406\u64cd\u4f5c\n    flush_rewrite_rules();\n}<\/code><\/pre><h3 class=\"wp-block-heading\">\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u793a\u4f8b<\/h3><pre class=\"wp-block-code\"><code>\/\/ includes\/post-types.php\nfunction mcc_register_custom_post_types() {\n    $labels = array(\n        'name' =&gt; '\u9879\u76ee',\n        'singular_name' =&gt; '\u9879\u76ee',\n        'menu_name' =&gt; '\u9879\u76ee\u96c6'\n    );\n\n    $args = array(\n        'labels' =&gt; $labels,\n        'public' =&gt; true,\n        'has_archive' =&gt; true,\n        'supports' =&gt; array('title', 'editor', 'thumbnail'),\n        'show_in_rest' =&gt; true, \/\/ \u652f\u6301Gutenberg\u7f16\u8f91\u5668\n    );\n\n    register_post_type('project', $args);\n}\nadd_action('init', 'mcc_register_custom_post_types');<\/code><\/pre><h3 class=\"wp-block-heading\">\u81ea\u5b9a\u4e49\u5206\u7c7b\u6cd5\u793a\u4f8b<\/h3><pre class=\"wp-block-code\"><code>\/\/ includes\/taxonomies.php\nfunction mcc_register_custom_taxonomies() {\n    $labels = array(\n        'name' =&gt; '\u9879\u76ee\u5206\u7c7b',\n        'singular_name' =&gt; '\u9879\u76ee\u5206\u7c7b'\n    );\n\n    $args = array(\n        'labels' =&gt; $labels,\n        'hierarchical' =&gt; true,\n        'show_in_rest' =&gt; true,\n    );\n\n    register_taxonomy('project_category', 'project', $args);\n}\nadd_action('init', 'mcc_register_custom_taxonomies');<\/code><\/pre><h2 class=\"wp-block-heading\">\ud83c\udfa8 \u4e3b\u9898functions.php\u7684\u4f7f\u7528\u573a\u666f<\/h2><h3 class=\"wp-block-heading\">\u2705 \u9002\u5408\u653e\u5728\u4e3b\u9898\u4e2d\u7684\u60c5\u51b5<\/h3><ol class=\"wp-block-list\">\n<li><strong>\u4e3b\u9898\u7279\u5b9a\u7684\u5c55\u793a\u529f\u80fd<\/strong><\/li>\n<\/ol><ul class=\"wp-block-list\">\n<li>\u77ed\u4ee3\u7801(Shortcodes)<\/li>\n\n\n\n<li>\u5c0f\u5de5\u5177(Widgets)<\/li>\n\n\n\n<li>\u6a21\u677f\u6807\u7b7e\u51fd\u6570<\/li>\n<\/ul><ol class=\"wp-block-list\">\n<li><strong>\u4e0e\u4e3b\u9898\u6837\u5f0f\u7d27\u5bc6\u76f8\u5173\u7684\u529f\u80fd<\/strong><\/li>\n<\/ol><ul class=\"wp-block-list\">\n<li>\u81ea\u5b9a\u4e49\u989c\u8272\u9762\u677f<\/li>\n\n\n\n<li>\u5b57\u4f53\u9009\u62e9\u5668<\/li>\n\n\n\n<li>\u5e03\u5c40\u8bbe\u7f6e<\/li>\n<\/ul><h3 class=\"wp-block-heading\">\u274c \u4e0d\u9002\u5408\u653e\u5728\u4e3b\u9898\u4e2d\u7684\u60c5\u51b5<\/h3><pre class=\"wp-block-code\"><code>\/\/ \u274c \u4e0d\u8981\u8fd9\u6837\u505a - \u4e3b\u9898\u5207\u6362\u4f1a\u5bfc\u81f4\u6570\u636e\u95ee\u9898\nfunction theme_specific_cpt() {\n    register_post_type('theme_only_post_type', $args);\n}\nadd_action('init', 'theme_specific_cpt');<\/code><\/pre><h2 class=\"wp-block-heading\">\ud83d\udd27 \u6700\u4f73\u5b9e\u8df5\u5efa\u8bae<\/h2><h3 class=\"wp-block-heading\">1. <strong>\u6e05\u6670\u7684\u547d\u540d\u7ea6\u5b9a<\/strong><\/h3><pre class=\"wp-block-code\"><code>\/\/ \u4f7f\u7528\u524d\u7f00\u907f\u514d\u51b2\u7a81\nfunction myplugin_register_post_type() {\n    \/\/ \u4f60\u7684\u4ee3\u7801\n}\n\n\/\/ \u4f7f\u7528\u7c7b\u5c01\u88c5\nclass MyCustomContent {\n    public function register_post_types() {\n        \/\/ \u6ce8\u518c\u903b\u8f91\n    }\n}<\/code><\/pre><h3 class=\"wp-block-heading\">2. <strong>\u8003\u8651\u4f7f\u7528\u73b0\u6709\u5de5\u5177<\/strong><\/h3><ul class=\"wp-block-list\">\n<li><strong>Custom Post Type UI<\/strong> \u63d2\u4ef6 &#8211; \u5feb\u901f\u521b\u5efa<\/li>\n\n\n\n<li><strong>Advanced Custom Fields<\/strong> &#8211; \u5143\u5b57\u6bb5\u7ba1\u7406<\/li>\n\n\n\n<li><strong>Pods<\/strong> \u6216 <strong>Toolset<\/strong> &#8211; \u5b8c\u6574\u89e3\u51b3\u65b9\u6848<\/li>\n<\/ul><h3 class=\"wp-block-heading\">3. <strong>\u6027\u80fd\u4f18\u5316<\/strong><\/h3><pre class=\"wp-block-code\"><code>\/\/ \u53ea\u5728\u9700\u8981\u65f6\u52a0\u8f7d\nfunction load_custom_content_features() {\n    if (is_admin() || is_post_type_archive('project')) {\n        require_once MCC_PLUGIN_PATH . 'includes\/meta-fields.php';\n    }\n}\nadd_action('wp', 'load_custom_content_features');<\/code><\/pre><h2 class=\"wp-block-heading\">\ud83d\udcca \u51b3\u7b56\u77e9\u9635<\/h2><figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u573a\u666f<\/th><th>\u63a8\u8350\u4f4d\u7f6e<\/th><th>\u7406\u7531<\/th><\/tr><\/thead><tbody><tr><td>\u5546\u52a1\u7f51\u7ad9\u7684\u4ea7\u54c1\u5c55\u793a<\/td><td>\u63d2\u4ef6<\/td><td>\u6570\u636e\u9700\u8981\u6301\u4e45\u5316<\/td><\/tr><tr><td>\u4e3b\u9898\u7279\u5b9a\u7684\u4f5c\u54c1\u96c6<\/td><td>\u4e3b\u9898<\/td><td>\u4e0e\u8bbe\u8ba1\u7d27\u5bc6\u76f8\u5173<\/td><\/tr><tr><td>\u591a\u7ad9\u70b9\u4f7f\u7528\u7684\u529f\u80fd<\/td><td>\u63d2\u4ef6<\/td><td>\u53ef\u91cd\u7528\u6027<\/td><\/tr><tr><td>\u4e34\u65f6\u4fc3\u9500\u5185\u5bb9<\/td><td>\u4e3b\u9898<\/td><td>\u77ed\u671f\u4f7f\u7528<\/td><\/tr><\/tbody><\/table><\/figure><h2 class=\"wp-block-heading\">\ud83d\udca1 \u603b\u7ed3<\/h2><p><strong>\u9009\u62e9\u63d2\u4ef6\u7684\u7406\u7531\uff1a<\/strong><\/p><ul class=\"wp-block-list\">\n<li>\u6570\u636e\u5b89\u5168\u6027\u548c\u6301\u4e45\u6027<\/li>\n\n\n\n<li>\u66f4\u597d\u7684\u4ee3\u7801\u7ec4\u7ec7\u548c\u7ef4\u62a4<\/li>\n\n\n\n<li>\u529f\u80fd\u4e0e\u5c55\u793a\u5206\u79bb<\/li>\n\n\n\n<li>\u957f\u671f\u9879\u76ee\u7684\u53ef\u6269\u5c55\u6027<\/li>\n<\/ul><p>\u53ea\u6709\u5728\u529f\u80fd\u786e\u5b9e\u4e0e\u7279\u5b9a\u4e3b\u9898\u7684\u89c6\u89c9\u8868\u73b0\u7d27\u5bc6\u8026\u5408\u65f6\uff0c\u624d\u8003\u8651\u653e\u5728\u4e3b\u9898\u7684<code>functions.php<\/code>\u4e2d\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u5728WordPress\u4e2d\uff0c\u5c06\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u3001\u81ea\u5b9a\u4e49\u5206\u7c7b\u6cd5\u548c\u5143\u6570\u636e\u5b57\u6bb5\u653e\u5728\u63d2\u4ef6\u4e2d\u901a\u5e38\u662f\u66f4\u5408\u9002\u7684\u9009\u62e9\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u5206\u6790\u548c\u5efa\u8bae\uff1a \ud83c\udfaf \u6838\u5fc3\u7ed3\u8bba\uff1a\u4f18\u5148\u9009\u62e9\u63d2\u4ef6 \u2705 \u63d2\u4ef6\u65b9\u5f0f\u7684\u4f18\u52bf \ud83d\udcc1 \u4ee3\u7801\u7ed3\u6784\u793a\u4f8b \u63d2\u4ef6\u76ee\u5f55\u7ed3\u6784 \u4e3b\u63d2\u4ef6\u6587\u4ef6 \u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u793a\u4f8b \u81ea\u5b9a\u4e49\u5206\u7c7b\u6cd5\u793a\u4f8b \ud83c\udfa8 \u4e3b\u9898functions.php\u7684\u4f7f\u7528\u573a\u666f \u2705 \u9002\u5408\u653e\u5728\u4e3b\u9898\u4e2d\u7684\u60c5\u51b5..<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3184],"tags":[],"tuisongtax":[],"class_list":["post-4707","post","type-post","status-publish","format-standard","hentry","category-zddj"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/4707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/comments?post=4707"}],"version-history":[{"count":0,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/4707\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=4707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/categories?post=4707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=4707"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=4707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}