{"id":8423,"date":"2016-01-14T20:19:33","date_gmt":"2016-01-15T01:19:33","guid":{"rendered":"httpss:\/\/www.powenko.com\/wordpress\/?p=8423"},"modified":"2016-01-14T20:23:06","modified_gmt":"2016-01-15T01:23:06","slug":"02%e5%9c%a8-page-%e6%96%b0%e5%a2%9e%e6%96%87%e7%ab%a0%e6%99%82%ef%bc%8c%e5%a4%9a%e5%80%8b%e6%ac%84%e4%bd%8d","status":"publish","type":"post","link":"https:\/\/www.powenko.com\/wordpress\/?p=8423","title":{"rendered":"02\u5728 Page \u65b0\u589e\u6587\u7ae0\u6642\uff0c\u591a\u500b\u6b04\u4f4d"},"content":{"rendered":"<p>\u5728 Page \u65b0\u589e\u6587\u7ae0\u6642\uff0c\u591a\u500b\u6b04\u4f4d<\/p>\n<p><a href=\"httpss:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen_Shot_2016-01-14_at_5_15_05_PM.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"httpss:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen_Shot_2016-01-14_at_5_15_05_PM.jpg\" alt=\"Screen_Shot_2016-01-14_at_5_15_05_PM\" width=\"570\" height=\"488\" class=\"alignnone size-full wp-image-8424\" srcset=\"https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen_Shot_2016-01-14_at_5_15_05_PM.jpg 570w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen_Shot_2016-01-14_at_5_15_05_PM-300x257.jpg 300w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen_Shot_2016-01-14_at_5_15_05_PM-316x271.jpg 316w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen_Shot_2016-01-14_at_5_15_05_PM-120x103.jpg 120w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen_Shot_2016-01-14_at_5_15_05_PM-210x180.jpg 210w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen_Shot_2016-01-14_at_5_15_05_PM-496x425.jpg 496w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen_Shot_2016-01-14_at_5_15_05_PM-140x120.jpg 140w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/a><\/p>\n<p>\u539f\u59cb\u7a0b\u5f0f\u3002\u53ef\u4ee5\u5728\u6b64<a href=\"httpsss:\/\/bitbucket.org\/powenko\/wordpress_plugins_widget_samplecodes\/src\/c41b3c047f64dc380ff7fe2dfeaccb42cbdfab7a\/02Page_meta\/?at=master\">\u4e0b\u8f09<\/a><\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n\r\n\/*\r\nPlugin Name: PowenKo  Page POST  Meta\r\nPlugin URI: httpss:\/\/wordpress.org\/plugins\/hello-dolly\/\r\nDescription: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from &lt;cite&gt;Hello, Dolly&lt;\/cite&gt; in the upper right of your admin screen on every page.\r\nAuthor: Powen Ko\r\nVersion: 1.6\r\nAuthor URI: httpss:\/\/ma.tt\/\r\n*\/\r\n\r\n\r\n\r\n\r\n\r\n\/* \u5c0f\u7bc4\u4f8b\uff1a\u5efa\u7acb\u82f1\u6587\u9078\u55ae\u6a19\u984c *\/\r\nadd_action('admin_init', 'admin_init_fn');  \/\/ \u6307\u5b9a\u5f8c\u53f0\u521d\u59cb\u5316\u6642\u8981\u57f7\u884c\u6211\u5011\u81ea\u8a02\u7684\u51fd\u5f0fadmin_init_fn\r\n \r\nfunction admin_init_fn()\r\n{\r\n    \/\/ \u4f7f\u7528add_meta_box\u4f86\u589e\u52a0\u4e00\u500b\u300c\u81ea\u8a02\u5340\u584a\u300d\uff0c\u5728callback\u7684\u53c3\u6578\u4f4d\u7f6e\uff0c\u653e\u4e0a\u6211\u5011\u81ea\u8a02\u7684\u51fd\u5f0f EnTitleCB_fn\r\n    add_meta_box('EnTitle', 'Powen Ko \u82f1\u6587\u6a19\u984c', 'EnTitleCB_fn', 'page', 'normal', 'high', null);\r\n}\r\n \r\n\/\/ \u7576WP\u8981\u756b\u51fa\u81ea\u8a02\u5340\u584a\u6642\uff0c\u5c31\u6703\u57f7\u884cadd_meta_box\u6307\u5b9a\u7684\u9019\u500bcallback\u51fd\u5f0f\r\nfunction EnTitleCB_fn()\r\n{\r\n    \/\/ \u9700\u8981\u53d6\u5f97\u76ee\u524d\u7de8\u8f2f\u7684post\u8cc7\u8a0a\uff0c\u5982id\r\n    global $post;\r\n    \/\/ \u628a\u6211\u5011\u81ea\u8a02\u7684Post Meta\u5f9e\u8cc7\u6599\u5eab\u53d6\u51fa\uff0c\u5f85\u6703\u653e\u9032\u6b04\u4f4d\r\n    \/\/ \u770b\u4f60\u9700\u8981\u591a\u5c11\u6b04\u4f4d\uff0c\u5c31\u8981\u57f7\u884c\u5e7e\u6b21get_post_meta()\u4f86\u53d6\u503c\r\n    $entitle_cnt = get_post_meta( $post-&gt;ID, 'EnTitle', true );\r\n?&gt;\r\n    &lt;th scope=&quot;row&quot;&gt;\u4e3b\u9078\u55ae\u82f1\u6587\u6a19\u984c\uff1a&lt;\/th&gt;\r\n        &lt;td&gt;\r\n            &lt;!-- \u958b\u59cb\u756b\u51faUI\uff0c\u770b\u4f60\u9700\u8981\u591a\u5c11\u6b04\u4f4d\uff0c\u5c31\u756b\u591a\u5c11input\u51fa\u4f86 --&gt;\r\n            &lt;label for=&quot;EnTitle&quot;&gt;\r\n            &lt;input id=&quot;EnTitle&quot; type=&quot;text&quot; size=&quot;75&quot; name=&quot;EnTitle&quot; value=&quot;&lt;?php echo $entitle_cnt;?&gt;&quot; \/&gt;\r\n            &lt;br \/&gt;&lt;em&gt;\u8aaa\u660e\uff1a\u8a2d\u5b9a\u5206\u9801\u51fa\u73fe\u5728\u9078\u55ae\u6642\u7684\u82f1\u6587\u7ffb\u8b6f\u3002&lt;\/em&gt;\r\n            &lt;\/label&gt;\r\n        &lt;\/td&gt;\r\n    &lt;\/tr&gt;\r\n&lt;?php\r\n}\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\nadd_action('wp_insert_post', 'insert_post_fn', 10, 2); \/\/ \u8b93WP\u5728\u65b0\u589e\u6587\u7ae0\u5167\u5bb9\u6642\uff0c\u4e5f\u57f7\u884c\u6211\u5011\u5b9a\u7fa9\u7684insert_post_fn\r\n \r\nfunction insert_post_fn($post_id, $post = null)\r\n{\r\n    \/\/ 'EnTitle'\u662f\u6211\u5011\u5b9a\u7fa9\u7684input\u7684name\uff0c\u5982\u679c\u9084\u6709\u5176\u4ed6\u7684\u6b04\u4f4d\uff0c\u5c31\u628a\u5b83\u5011\u7684name\u52a0\u5165\u3002\r\n    \/\/ \u5982 array(&quot;EnTitle&quot;,&quot;aaa&quot;,&quot;bbb&quot;); \u4e0b\u65b9\u7684\u7a0b\u5f0f\u78bc\u5c31\u6703\u4ee5\u8ff4\u5708\u4f86\u8655\u7406\u9663\u5217\u4e2d\u7684\u6bcf\u500binput\u503c\r\n    $meta_post_fields = array(&quot;EnTitle&quot;); \r\n    $goloop = true;\r\n     \r\n    \/\/ \u5982\u679c\u662f\u6211\u5011\u8981\u8655\u7406\u7684\u5167\u5bb9\u578b\u5225-page \u5c31\u8655\u7406\u5b83\r\n    if ($post-&gt;post_type == &quot;page&quot;)\r\n    {\r\n        $mfs = $meta_post_fields;\r\n        $goloop = true;\r\n    }\r\n\r\n     \r\n    if ($goloop)\r\n    {\r\n        \/\/ \u53d6\u5f97Post\u9032\u4f86\u7684\u6b04\u4f4d\u8cc7\u6599\uff0c\u91dd\u5c0d\u6211\u5011\u81ea\u8a02\u7684\u6b04\u4f4d$meta_fields\r\n        foreach ($mfs as $key)\r\n        {\r\n            \/\/ \u5982\u679c\u6709\u7a7a\u503c\u5c31\u4e0d\u9032\u884c\u8655\u7406\r\n            $value = @$_POST&#x5B;$key];\r\n            if (empty($value))\r\n            {\r\n                delete_post_meta($post_id, $key);\r\n                continue;\r\n            }\r\n \r\n            \/\/ \u5982\u679c\u4e1f\u904e\u4f86\u7684\u53c3\u6578\u4e0d\u662f\u9663\u5217\r\n            if (!is_array($value))\r\n            {\r\n                \/\/ \u66f4\u65b0\u8cc7\u6599\uff0c\u82e5\u7121\u6cd5\u66f4\u65b0\uff0c\u4ee3\u8868\u662f\u8981\u65b0\u589e\u8cc7\u6599\r\n                if (!update_post_meta($post_id, $key, $value))\r\n                {\r\n                    add_post_meta($post_id, $key, $value);\r\n                }\r\n            }\r\n            else\r\n            {\r\n                \/\/ \u5982\u679c\u4e1f\u904e\u4f86\u7684\u53c3\u6578\u662f\u9663\u5217\uff0c\u5148\u522a\u9664\u4e4b\u524d\u7684\u503c\uff0c\u518d\u4e00\u500b\u500b\u5efa\u9032\u76f8\u540c\u540d\u7a31\u7684post meta\r\n                delete_post_meta($post_id, $key);\r\n                 \r\n                \/\/ Loop through the array adding new values to the post meta as different entries with the same name\r\n                foreach ($value as $entry)\r\n                {\r\n                    add_post_meta($post_id, $key, $entry);\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\n\r\nfunction remove_post_custom_fields() {\r\n    remove_meta_box( 'postcustom' , 'post' , 'normal' ); \r\n}\r\nadd_action( 'admin_menu' , 'remove_post_custom_fields' );\r\n\r\n\r\n\r\n\r\n?&gt;\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Page \u65b0\u589e\u6587\u7ae0\u6642\uff0c\u591a\u500b\u6b04\u4f4d \u539f\u59cb\u7a0b\u5f0f\u3002\u53ef\u4ee5\u5728\u6b64\u4e0b\u8f09 &lt;?php \/* Plugin Name:  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8424,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[],"class_list":["post-8423","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ch13meta-box"],"_links":{"self":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8423"}],"collection":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8423"}],"version-history":[{"count":3,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8423\/revisions"}],"predecessor-version":[{"id":8427,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8423\/revisions\/8427"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/8424"}],"wp:attachment":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}