{"id":15094,"date":"2020-04-09T23:02:18","date_gmt":"2020-04-09T15:02:18","guid":{"rendered":"https:\/\/www.npc.ink\/?p=15094"},"modified":"2020-10-26T11:49:23","modified_gmt":"2020-10-26T03:49:23","slug":"%e6%b7%bb%e5%8a%a0%e7%ac%ac%e4%b8%80%e4%b8%aa%e8%87%aa%e5%ae%9a%e4%b9%89%e9%80%89%e9%a1%b9-wordpress-customize-api","status":"publish","type":"post","link":"https:\/\/www.npc.ink\/15094.html","title":{"rendered":"WordPress Customize API - \u6dfb\u52a0\u7b2c\u4e00\u4e2a\u81ea\u5b9a\u4e49\u9009\u9879"},"content":{"rendered":"\n

\u8fd9\u4e2aWordPress Customize API<\/strong><\/a>\u662fwordpress\u81ea\u5e26\u7684\u4e3a\u5f00\u53d1\u8005\u51c6\u5907\u7684\u4e00\u5957API\uff0c\u901a\u8fc7\u8fd9\u4e2a\uff0cwordpress\u5f00\u53d1\u8005\u4eec\u53ef\u4ee5\u5f00\u53d1\u51fa\u4e0d\u540c\u7684\u4e3b\u9898\u6216\u662f\u63d2\u4ef6\u8bbe\u7f6e\u9009\u9879\uff0c\u65b9\u4fbf\u60a8\u7684\u4e3b\u9898\u7528\u6237\u81ea\u5b9a\u4e49\u4e3b\u9898\u3002\u90a3\u4e48\u8fd9\u6837\u4e00\u4e2a\u4e1c\u897f\u8be5\u5982\u4f55\u4f7f\u7528\u5462\uff1f\u8fd9\u4e00\u8282\u7684wordpress\u5f00\u53d1<\/strong><\/a>\u6559\u7a0b\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u4ea4\u6d41\u4e0b\u3002<\/p>\n\n\n\n

\"WordPress
\u80cc\u666f\u56fe\u7247<\/figcaption><\/figure><\/div>\n\n\n\n

\u4ecb\u7ecd\uff1a<\/h2>\n\n\n\n

WordPress\u5b9a\u5236\u5668\u5141\u8bb8\u7528\u6237\u4fee\u6539\u548c\u914d\u7f6e\u4e3b\u9898\u9009\u9879\uff0c\u540c\u65f6\u8fd8\u4e3a\u4ed6\u4eec\u63d0\u4f9b\u8fd9\u4e9b\u66f4\u6539\u7684\u5b9e\u65f6\u9884\u89c8\u3002\u5b9a\u5236\u7a0b\u5e8f\u65e8\u5728\u4e3a\u4e3b\u9898\u5f00\u53d1\u4eba\u5458\u63d0\u4f9b\u4e00\u4e2a\u6807\u51c6\u754c\u9762\uff0c\u4f9b\u4ed6\u4eec\u5728\u4e3b\u9898\u5185\u63d0\u4f9b\u81ea\u5b9a\u4e49\u9009\u9879\u65f6\u4f7f\u7528\u3002<\/p>\n\n\n\n

\u9996\u5148\uff0c\u4f60\u73b0\u5728\u4e00\u5b9a\u6bd4\u8f83\u61f5\uff0c\u6ca1\u5173\u7cfb\uff0c\u6211\u4eec\u5148\u770b\u770b\u8fd9\u4e2a\u6240\u8c13\u7684WordPress Customize API<\/strong><\/a>\u53ef\u4ee5\u505a\u54ea\u4e9b\u4e8b\u60c5\u5427\uff0c\u4e0b\u9762\u8fd9\u5f20\u56fe\u662f\u6211\u5236\u4f5c\u7684\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n\n\n\n

\"WordPress
WordPress Settings API\u529f\u80fd\u6f14\u793a<\/figcaption><\/figure><\/div>\n\n\n\n

\u5982\u679c\u4f60\u5f00\u53d1\u7684wordpress\u4e3b\u9898\u9700\u8981\u7684\u529f\u80fd\u4e0d\u591a\uff0c\u90a3\u4e48\u8fd9\u4e9b\u9009\u9879\u8db3\u591f\u6211\u4eec\u4f7f\u7528\u4e86\u3002<\/p>\n\n\n\n

\u6b63\u6587\u5f00\u59cb\uff1a<\/h2>\n\n\n\n

\u6211\u4eec\u5148\u660e\u767d\u4e00\u4e9b\u6982\u5ff5\uff0c\u9762\u677f\u3001\u8282\u3001\u8bbe\u7f6e\u548c\u63a7\u4ef6\uff0c\u4ed6\u4eec\u7684\u5173\u7cfb\u7c7b\u4f3c\u8fd9\u6837\uff1a<\/p>\n\n\n\n

\"WordPress
WordPress Settings API - \u9762\u677f\u3001\u8282\u3001\u8bbe\u7f6e\u548c\u63a7\u4ef6\u5173\u7cfb\u56fe<\/figcaption><\/figure><\/div>\n\n\n\n

\u9762\u677f<\/h2>\n\n\n\n

\u9762\u677f\u5c55\u793a\u5728\u81ea\u5b9a\u4e49\u9762\u677f\u7684\u9996\u9875\uff0c\u4e5f\u5c31\u662f\u8fd9\u91cc\uff1a<\/p>\n\n\n\n

\"WordPress
WordPress Settings API - \u9762\u677f<\/figcaption><\/figure><\/div>\n\n\n\n

\u8282<\/h2>\n\n\n\n

\u90a3\u4e48\uff0c\u4ec0\u4e48\u662f\u8282\u5462\uff1f\u6839\u636e\u4e0a\u56fe\u53ef\u77e5\uff0c\u8282\u5728\u9762\u677f\u4e0b\u9762\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n

\"WordPress
WordPress Settings API - \u8282<\/figcaption><\/figure><\/div>\n\n\n\n

\u90a3\u4e48\u8bbe\u7f6e\u548c\u63a7\u4ef6\u5462\uff1f<\/h2>\n\n\n\n

\u8bbe\u7f6e\u548c\u63a7\u4ef6\u662f\u5728\u4e00\u8d77\u7684\u597d\u642d\u6863\uff0c\u53ef\u4ee5\u8fd9\u4e48\u7406\u89e3\uff0c\u201c\u8bbe\u7f6e\u201d\u5148\u6316\u6d1e\uff0c\u7136\u540e\u201c\u63a7\u4ef6\u201d\u628a\u201c\u529f\u80fd\u201d\uff0c\u57cb\u8fdb\u53bb\uff0c\u4e00\u4e2a\u201c\u8bbe\u7f6e\u201d\u53ea\u80fd\u6316\u4e00\u4e2a\u6d1e\uff0c\u800c\u4e00\u4e2a\u63a7\u4ef6\u53ea\u80fd\u628a\u4e00\u4e2a\u529f\u80fd\u57cb\u8fdb\u53bb\u3002\u8fd9\u5c31\u662f\u8bbe\u7f6e\u4e0e\u63a7\u4ef6\u95f4\u7684\u5173\u7cfb\u4e86\u3002<\/p>\n\n\n\n

\u8bbe\u7f6e\u548c\u63a7\u4ef6\u662f\u5728\u8282\u7684\u4e0b\u9762\uff0c\u800c\u4e14\u8bbe\u7f6e\u548c\u63a7\u4ef6\u662f\u5f85\u5728\u4e00\u8d77\u7684\u3002\u8bf4\u4e86\u90a3\u4e48\u591a\uff0c\u6765\u5b9e\u6218\u5427\u3002<\/p>\n\n\n\n

\u5b9e\u6218<\/h2>\n\n\n\n

\u4ee5wordpress\u81ea\u5e26\u76842019\u4e3b\u9898\u4e3a\u4f8b\u5b50\uff0c\u57282019\u4e3b\u9898\u6839\u76ee\u5f55\u4e0b\u7684functions.php<\/code>\u6587\u4ef6\u7684<?<\/code>\u4e0b\u9762\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n\n\n\n

\/\/\u6dfb\u52a0\u81ea\u5b9a\u4e49\u8bbe\u7f6e\u9009\u9879\nfunction npcink_customize_register( $wp_customize ) {\n\t\/\/\u7ed9\u76f8\u5173\u8bbe\u7f6e\u9879\u76ee\u52a0\u5c0f\u94c5\u7b14\n\n\tif ( isset( $wp_customize->selective_refresh ) ) {\n\n\t\/\/One\n\t$wp_customize->selective_refresh->add_partial( 'npcink_sections_text_one', array(\n\t\t'selector'        => '.1-1',\n\t\t'render_callback' => 'lifet_customize_partial_npcink_sections_text_one',\n\t) );\n\n\t\/\/Two\n\t\t$wp_customize->selective_refresh->add_partial( 'npcink_sections_text_two', array(\n\t\t\t'selector'        => '.1-2',\n\t\t\t'render_callback' => 'lifet_customize_partial_npcink_sections_text_two',\n\t\t) );\n\t\t\n\t}\n\t\n\n\t\/\/-----------------------------------------------------------------------------\n\t\/\/\u6dfb\u52a0\u4e3b\u9898\u8bbe\u7f6e\u9762\u677f\uff0cID = npcink_options\n\t$wp_customize->add_panel( 'npcink_options',\n\tarray(\n\t\t'title' => __( '\u6211\u662f\u9762\u677f - Npcink', 'npcink' ),\n\t\t'description' => __( 'Npcink\u9996\u53d1\uff0cMuze\u539f\u521b', 'npcink' ),\n\t\t'priority'    => 30,\n\t\t'capabitity'  => 'edit_theme_options',\n\t) );\n\n\t\/\/\u6dfb\u52a0\u6587\u672c\u8bbe\u7f6e\u8282\uff0cID = npcink_sections_text\n\t$wp_customize->add_section('npcink_sections_text',\n\tarray(                \n\t\t'title'     => '\u8282 - Npcink',\n\t\t'description' => '\u4e3b\u9898\u7684\u6587\u672c\u8bbe\u7f6e',     \n\t\t'panel' => 'npcink_options',\n\t) );\n\n\t\/\/\u6587\u5b57\u8bbe\u7f6e:one\uff0cID = npcink_sections_text_one\n\t$wp_customize->add_setting('npcink_sections_text_one',\n\t\tarray(\n\t\t\t'default' => 'Npcink \u8363\u8a89\u51fa\u54c1',\n\t\t)\n\t);\n\t$wp_customize->add_control('npcink_sections_text_one',\n\t\tarray(\n\t\t\t'label' => '\u6587\u672c\u8bbe\u7f6e\uff1aOne',\n\t\t\t'section' => 'npcink_sections_text',\n\t\t\t'type' => 'text',\n\t\t)\n\t);\n\n\t\/\/\u6587\u5b57\u8bbe\u7f6e:two\uff0cID = npcink_sections_text_two\n\t$wp_customize->add_setting('npcink_sections_text_two',\n\t\tarray(\n\t\t\t'default' => 'Npcink \u8363\u8a89\u51fa\u54c1',\n\t\t)\n\t);\n\t$wp_customize->add_control('npcink_sections_text_two',\n\t\tarray(\n\t\t\t'label' => '\u6587\u672c\u8bbe\u7f6e\uff1aTwo',\n\t\t\t'section' => 'npcink_sections_text',\n\t\t\t'type' => 'text',\n\t\t)\n\t);\n\n}\nadd_action( 'customize_register', 'npcink_customize_register' );<\/code><\/pre>\n\n\n\n

\u4fdd\u5b58\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5728\u7f51\u7ad9\u540e\u53f0 \u2192 \u5916\u89c2 \u2192 \u81ea\u5b9a\u4e49\u4e2d\u770b\u5230\u6211\u4eec\u6dfb\u52a0\u7684\u65b0\u9009\u9879\uff1a\u6211\u662f\u9762\u677f - Npcink\u3002<\/p>\n\n\n\n

\u4e3a\u4e86\u65b9\u4fbf\u770b\u5230\u6f14\u793a\u6548\u679c\uff0c\u6211\u4eec\u5728\u4e3b\u9898\u6839\u76ee\u5f55\u4e0b\u7684header.php<\/code>\u6587\u4ef6\u5e95\u90e8\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n\n\n\n

<dl style=\"padding: 1em;\">\n    <dd class=\"1-1\">1-1\uff1a<?php echo get_theme_mod( 'npcink_sections_text_one', 'Npcink\u8363\u8a89\u51fa\u54c1' ); ?><\/dd>\n    <dd class=\"1-2\">1-2\uff1a<?php echo get_theme_mod( 'npcink_sections_text_two', 'Npcink\u8363\u8a89\u51fa\u54c1' ); ?><\/dd>\n<\/dl><\/code><\/pre>\n\n\n\n

\u4fdd\u5b58\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u5237\u65b0\u4e0b\u81ea\u5b9a\u4e49\uff0c\u60a8\u5c31\u53ef\u4ee5\u5728\u81ea\u5b9a\u4e49\u4e2d\u770b\u5230\u8fd9\u4e2a\u6548\u679c\uff1a<\/p>\n\n\n\n

\"WordPress
WordPress Settings API - \u8282\u548c\u63a7\u4ef6<\/figcaption><\/figure><\/div>\n\n\n\n

\u5230\u8fd9\u91cc\u4e3a\u6b62\uff0c\u60a8\u5df2\u7ecf\u77e5\u9053\u4e86WordPress Customize API<\/strong><\/a>\u7684\u9762\u677f\u3001\u8282\u3001\u8bbe\u7f6e\u548c\u63a7\u4ef6\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u77e5\u9053\u4e86\u5982\u4f55\u8ddf\u7740\u6559\u7a0b\u505a\u51fa\u4e00\u4e2a\u8bbe\u7f6e\u51fa\u6765\u5e76\u8c03\u7528\u4e86\uff0c\u90a3\u4e48\u4e0a\u9762\u4e2d\u6dfb\u52a0\u7684\u4ee3\u7801\u90fd\u6709\u5565\u7528\u5462\uff1f\u8feb\u4e8e\u7bc7\u5e45\u5c31\u4e0d\u5728\u6b64\u5904\u63d0\u53ca\uff0c\u8bf7\u770b\u4e0b\u6587\u3002<\/p>\n\n\n\n

\u63a8\u8350\uff1a<\/h2>\n\n\n\n

\u8fd9\u4e2a\u539f\u751f\u8bbe\u7f6e\u6846\u67b6\u4f18\u70b9\u662f\u4f53\u79ef\u5c0f\uff0c\u8f7b\u91cf\uff0c\u80fd\u7528\uff0c\u5982\u679c\u60a8\u9700\u8981\u66f4\u52a0\u4e30\u5bcc\u548c\u4e13\u4e1a\u7684\u529f\u80fd\uff0c\u90a3\u4e48\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u8fd9\u6b3ewordpress\u8bbe\u7f6e\u6846\u67b6\uff1a<\/p>\n\n\n

\r\n \r\n \"WordPress<\/picture>\r\n <\/span>
\r\n \r\n \"WordPress<\/picture>\r\n <\/a>\r\n <\/div><\/a><\/a>
\r\n

Kirki - wordpress\u8bbe\u7f6e\u6846\u67b6<\/a><\/h2>\r\n