{"id":8431,"date":"2016-01-14T20:38:29","date_gmt":"2016-01-15T01:38:29","guid":{"rendered":"httpss:\/\/www.powenko.com\/wordpress\/?p=8431"},"modified":"2016-01-14T20:43:07","modified_gmt":"2016-01-15T01:43:07","slug":"04%e5%9c%a8-pagepost%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%e4%b8%a6%e4%b8%94%e9%a1%af%e7%a4%ba%e5%9c%a8%e6%96%87%e7%ab%a0%e4%b8%8a","status":"publish","type":"post","link":"https:\/\/www.powenko.com\/wordpress\/?p=8431","title":{"rendered":"04\u5728 PagePost\u65b0\u589e\u6587\u7ae0\u6642\uff0c\u591a\u500b\u6b04\u4f4d\u4e26\u4e14\u986f\u793a\u5728\u6587\u7ae0\u4e0a"},"content":{"rendered":"<p><a href=\"httpss:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.09-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8432\" src=\"httpss:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.09-PM.png\" alt=\"Screen Shot 2016-01-14 at 5.35.09 PM\" width=\"332\" height=\"132\" srcset=\"https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.09-PM.png 332w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.09-PM-300x119.png 300w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.09-PM-316x126.png 316w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.09-PM-120x48.png 120w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.09-PM-210x83.png 210w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.09-PM-140x56.png 140w\" sizes=\"(max-width: 332px) 100vw, 332px\" \/><\/a><\/p>\n<p><a href=\"httpss:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.03-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8433\" src=\"httpss:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.03-PM.png\" alt=\"Screen Shot 2016-01-14 at 5.35.03 PM\" width=\"431\" height=\"262\" srcset=\"https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.03-PM.png 431w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.03-PM-300x182.png 300w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.03-PM-316x192.png 316w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.03-PM-120x73.png 120w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.03-PM-210x128.png 210w, https:\/\/www.powenko.com\/wordpress\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-14-at-5.35.03-PM-140x85.png 140w\" sizes=\"(max-width: 431px) 100vw, 431px\" \/><\/a><br \/>\n\u539f\u59cb\u7a0b\u5f0f\u3002\u53ef\u4ee5\u5728\u6b64<a href=\"httpsss:\/\/bitbucket.org\/powenko\/wordpress_plugins_widget_samplecodes\/src\/726e669731f68a30813192dfdf9594f2bce4d1c3\/05Meta_Post_Displaymeta\/?at=master\">\u4e0b\u8f09<\/a><\/p>\n<pre><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\t\/\/ add_meta_box('EnTitle', 'Powen Ko \u82f1\u6587\u6a19\u984c', 'EnTitleCB_fn', 'post', 'normal', 'high', null);\r\n\t\r\n\t$types = array( 'post', 'page', 'custom-type' );\r\n\r\nforeach( $types as $type ) {\r\n    \/\/  add_meta_box('EnTitle', 'Powen Ko \u82f1\u6587\u6a19\u984c', 'EnTitleCB_fn', $type, 'side');\r\n\t   add_meta_box('EnTitle', 'Powen Ko \u82f1\u6587\u6a19\u984c', 'EnTitleCB_fn', $type, 'normal', 'high', null);\r\n}\r\n\r\n\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\tif ($post-&gt;post_type == &quot;post&quot;)\r\n    {\r\n        $mfs = $meta_post_fields;\r\n        $goloop = true;\r\n    }\r\n\r\n      \/\/  $mfs = $meta_post_fields;\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\/\/ This just echoes the chosen line, we'll position it later\r\nfunction hello_dolly($input) {\r\n\t  \/\/ \u9700\u8981\u53d6\u5f97\u76ee\u524d\u7de8\u8f2f\u7684post\u8cc7\u8a0a\uff0c\u5982id\r\n    global $post;\r\n\techo $input ;\r\n    echo '\u4e3b\u9078\u55ae\u82f1\u6587\u6a19\u984c\uff1a'.get_post_meta( $post-&gt;ID, 'EnTitle', true );\r\n}\r\n\r\nadd_filter( 'the_content', 'hello_dolly' );\r\n\r\n\r\n\r\n\r\n\r\n?&gt;\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u59cb\u7a0b\u5f0f\u3002\u53ef\u4ee5\u5728\u6b64\u4e0b\u8f09 &lt;?php \/* Plugin Name: PowenKo Page POST  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8433,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[],"class_list":["post-8431","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\/8431"}],"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=8431"}],"version-history":[{"count":3,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8431\/revisions"}],"predecessor-version":[{"id":8436,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8431\/revisions\/8436"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/8433"}],"wp:attachment":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}