﻿{"id":405,"date":"2014-06-06T13:26:35","date_gmt":"2014-06-06T05:26:35","guid":{"rendered":"http:\/\/www.wuhaibin.com\/blog\/?p=405"},"modified":"2014-08-29T15:04:51","modified_gmt":"2014-08-29T07:04:51","slug":"%e7%94%a8%e4%bb%a3%e7%a0%81%e5%ae%9e%e7%8e%b0wordpress%e6%96%87%e7%ab%a0%e6%b5%8f%e8%a7%88%e6%ac%a1%e6%95%b0%e7%bb%9f%e8%ae%a1%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"http:\/\/www.wuhaibin.com\/blog\/work\/wordpress\/405.html","title":{"rendered":"\u7528\u4ee3\u7801\u5b9e\u73b0WordPress\u6587\u7ae0\u6d4f\u89c8\u6b21\u6570\u7edf\u8ba1\u529f\u80fd"},"content":{"rendered":"<div class=\"published\" style=\"margin: 0px 10px 20px; padding: 0px; border: 0px; outline: none; position: relative; width: 620px; text-align: center; color: #666666; font-family: \u5fae\u8f6f\u96c5\u9ed1, serif; line-height: normal; background-image: url('http:\/\/www.wpbus.com.cn\/wp-content\/themes\/periodic\/images\/backgrounds\/bg-published.gif'); background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: 0px 0px; background-repeat: repeat-x;\"><a href=\"http:\/\/www.wpbus.com.cn\/wp-content\/uploads\/2012\/12\/%E7%94%A8%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0WordPress%E6%96%87%E7%AB%A0%E6%B5%8F%E8%A7%88%E6%AC%A1%E6%95%B0%E7%BB%9F%E8%AE%A1%E5%8A%9F%E8%83%BD.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter\" data-original=\"http:\/\/www.wpbus.com.cn\/wp-content\/uploads\/2012\/12\/%E7%94%A8%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0WordPress%E6%96%87%E7%AB%A0%E6%B5%8F%E8%A7%88%E6%AC%A1%E6%95%B0%E7%BB%9F%E8%AE%A1%E5%8A%9F%E8%83%BD.png\" src=\"http:\/\/www.wuhaibin.com\/blog\/wp-content\/themes\/Ality\/img\/loading.gif\" alt=\"\" width=\"610\" height=\"225\" \/><\/a><\/div>\n<noscript><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter\" src=\"http:\/\/www.wpbus.com.cn\/wp-content\/uploads\/2012\/12\/%E7%94%A8%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0WordPress%E6%96%87%E7%AB%A0%E6%B5%8F%E8%A7%88%E6%AC%A1%E6%95%B0%E7%BB%9F%E8%AE%A1%E5%8A%9F%E8%83%BD.png\" alt=\"\" width=\"610\" height=\"225\" \/><\/a><\/div><\/noscript>\n<div class=\"published\" style=\"margin: 0px 10px 20px; padding: 0px; border: 0px; outline: none; position: relative; width: 620px; text-align: center; color: #666666; font-family: \u5fae\u8f6f\u96c5\u9ed1, serif; line-height: normal; background-image: url('http:\/\/www.wpbus.com.cn\/wp-content\/themes\/periodic\/images\/backgrounds\/bg-published.gif'); background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: 0px 0px; background-repeat: repeat-x;\"><span style=\"font-size: 1.4em; line-height: 1.7em;\">\u8fd9\u4e2a\u529f\u80fd\u76f8\u4fe1\u5927\u90e8\u5206\u535a\u5ba2\u90fd\u4f1a\u7528\u5230\uff0c\u4eca\u5929\u4ecb\u7ecd\u7684\u4f7f\u7528\u63d2\u5165\u4ee3\u7801\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\uff0c\u4ee3\u7801\u76f2\u6216\u8005\u61d2\u5f97\u6298\u817e\u4ee3\u7801\u7684\u7ae5\u978b\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u63d2\u4ef6\uff1a<\/span><a style=\"font-size: 1.4em; line-height: 1.7em; margin: 0px; padding: 0px; border: 0px; outline: none; text-decoration: none; color: #ff0000;\" href=\"http:\/\/www.wpbus.com.cn\/wp-postviews.html\" target=\"_blank\">WP-PostViews<\/a><\/div>\n<div class=\"post-2597 post type-post status-publish format-standard hentry category-wp-tutorial tag-statistics post-620 post-entry\" style=\"margin: 0px 10px; padding: 0px; border: 0px; outline: none; position: relative; width: 620px; font-family: \u5fae\u8f6f\u96c5\u9ed1, serif; line-height: normal;\">\n<p style=\"color: #666666; margin: 0px 0px 30px; padding: 0px; border: 0px; outline: none; font-size: 1.4em; line-height: 1.7em;\">\u9996\u5148\u8fdb\u5165WP\u540e\u53f0\uff0c\u4e3b\u9898 \u2013 \u7f16\u8f91\uff0c\u627e\u5230functions.php\u6587\u4ef6\uff0c\u5728\u9002\u5f53\u4f4d\u7f6e\u63d2\u5165\u4e0b\u9762\u4ee3\u7801\uff1a<\/p>\n<div class=\"codecolorer-container javascript railscasts\" style=\"color: #e6e1dc; margin: 0px 0px 10px; padding: 0px; border: 1px solid #9f9f9f; outline: none; font-size: 13px; line-height: 1.4em; font-family: Monaco, 'Lucida Console', monospace; overflow: auto; white-space: nowrap; background-color: #2b2b2b;\">\n<div class=\"javascript codecolorer\" style=\"margin: 0px; padding: 5px; border: 0px; outline: none; line-height: 1.4em;\"><span class=\"coMULTI\" style=\"font-style: italic; line-height: 1.4em; color: #bc9458;\">\/* Postviews start *\/<\/span>&nbsp;<\/p>\n<p><span class=\"kw2\" style=\"line-height: 1.4em; color: #cc7833;\">function<\/span>\u00a0getPostViews<span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span>$postID<span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">{<\/span><\/p>\n<p>$count_key\u00a0<span class=\"sy0\" style=\"line-height: 1.4em;\">=<\/span>\u00a0<span class=\"st0\" style=\"line-height: 1.4em; color: #a5c261;\">'post_views_count'<\/span><span class=\"sy0\" style=\"line-height: 1.4em;\">;<\/span><\/p>\n<p>$count\u00a0<span class=\"sy0\" style=\"line-height: 1.4em;\">=<\/span>\u00a0get_post_meta<span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span>$postID<span class=\"sy0\" style=\"line-height: 1.4em;\">,<\/span>\u00a0$count_key<span class=\"sy0\" style=\"line-height: 1.4em;\">,<\/span>\u00a0<span class=\"kw2\" style=\"line-height: 1.4em; color: #cc7833;\">true<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span><span class=\"sy0\" style=\"line-height: 1.4em;\">;<\/span><\/p>\n<p><span class=\"kw1\" style=\"line-height: 1.4em; color: #cc7833;\">if<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span>$count<span class=\"sy0\" style=\"line-height: 1.4em;\">==<\/span><span class=\"st0\" style=\"line-height: 1.4em; color: #a5c261;\">''<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">{<\/span><\/p>\n<p>delete_post_meta<span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span>$postID<span class=\"sy0\" style=\"line-height: 1.4em;\">,<\/span>\u00a0$count_key<span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span><span class=\"sy0\" style=\"line-height: 1.4em;\">;<\/span><\/p>\n<p>add_post_meta<span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span>$postID<span class=\"sy0\" style=\"line-height: 1.4em;\">,<\/span>\u00a0$count_key<span class=\"sy0\" style=\"line-height: 1.4em;\">,<\/span>\u00a0<span class=\"st0\" style=\"line-height: 1.4em; color: #a5c261;\">'0'<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span><span class=\"sy0\" style=\"line-height: 1.4em;\">;<\/span><\/p>\n<p><span class=\"kw1\" style=\"line-height: 1.4em; color: #cc7833;\">return<\/span>\u00a0<span class=\"st0\" style=\"line-height: 1.4em; color: #a5c261;\">\" 0 \"<\/span><span class=\"sy0\" style=\"line-height: 1.4em;\">;<\/span><\/p>\n<p><span class=\"br0\" style=\"line-height: 1.4em;\">}<\/span><\/p>\n<p><span class=\"kw1\" style=\"line-height: 1.4em; color: #cc7833;\">return<\/span>\u00a0$count<span class=\"sy0\" style=\"line-height: 1.4em;\">;<\/span><\/p>\n<p><span class=\"br0\" style=\"line-height: 1.4em;\">}<\/span><\/p>\n<p><span class=\"kw2\" style=\"line-height: 1.4em; color: #cc7833;\">function<\/span>\u00a0setPostViews<span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span>$postID<span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span>\u00a0<span class=\"br0\" style=\"line-height: 1.4em;\">{<\/span><\/p>\n<p>$count_key\u00a0<span class=\"sy0\" style=\"line-height: 1.4em;\">=<\/span>\u00a0<span class=\"st0\" style=\"line-height: 1.4em; color: #a5c261;\">'post_views_count'<\/span><span class=\"sy0\" style=\"line-height: 1.4em;\">;<\/span><\/p>\n<p>$count\u00a0<span class=\"sy0\" style=\"line-height: 1.4em;\">=<\/span>\u00a0get_post_meta<span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span>$postID<span class=\"sy0\" style=\"line-height: 1.4em;\">,<\/span>\u00a0$count_key<span class=\"sy0\" style=\"line-height: 1.4em;\">,<\/span>\u00a0<span class=\"kw2\" style=\"line-height: 1.4em; color: #cc7833;\">true<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span><span class=\"sy0\" style=\"line-height: 1.4em;\">;<\/span><\/p>\n<p><span class=\"kw1\" style=\"line-height: 1.4em; color: #cc7833;\">if<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span>$count<span class=\"sy0\" style=\"line-height: 1.4em;\">==<\/span><span class=\"st0\" style=\"line-height: 1.4em; color: #a5c261;\">''<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">{<\/span><\/p>\n<p>$count\u00a0<span class=\"sy0\" style=\"line-height: 1.4em;\">=<\/span>\u00a0<span class=\"nu0\" style=\"line-height: 1.4em; color: #6d9cbe;\">0<\/span><span class=\"sy0\" style=\"line-height: 1.4em;\">;<\/span><\/p>\n<p>delete_post_meta<span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span>$postID<span class=\"sy0\" style=\"line-height: 1.4em;\">,<\/span>\u00a0$count_key<span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span><span class=\"sy0\" style=\"line-height: 1.4em;\">;<\/span><\/p>\n<p>add_post_meta<span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span>$postID<span class=\"sy0\" style=\"line-height: 1.4em;\">,<\/span>\u00a0$count_key<span class=\"sy0\" style=\"line-height: 1.4em;\">,<\/span>\u00a0<span class=\"st0\" style=\"line-height: 1.4em; color: #a5c261;\">'0'<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span><span class=\"sy0\" style=\"line-height: 1.4em;\">;<\/span><\/p>\n<p><span class=\"br0\" style=\"line-height: 1.4em;\">}<\/span><span class=\"kw1\" style=\"line-height: 1.4em; color: #cc7833;\">else<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">{<\/span><\/p>\n<p>$count<span class=\"sy0\" style=\"line-height: 1.4em;\">++;<\/span><\/p>\n<p>update_post_meta<span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span>$postID<span class=\"sy0\" style=\"line-height: 1.4em;\">,<\/span>\u00a0$count_key<span class=\"sy0\" style=\"line-height: 1.4em;\">,<\/span>\u00a0$count<span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span><span class=\"sy0\" style=\"line-height: 1.4em;\">;<\/span><\/p>\n<p><span class=\"br0\" style=\"line-height: 1.4em;\">}<\/span><\/p>\n<p><span class=\"br0\" style=\"line-height: 1.4em;\">}<\/span><\/p>\n<p><span class=\"coMULTI\" style=\"font-style: italic; line-height: 1.4em; color: #bc9458;\">\/* Postviews start end*\/<\/span><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<p style=\"color: #666666; margin: 0px 0px 30px; padding: 0px; border: 0px; outline: none; font-size: 1.4em; line-height: 1.7em;\">\u7136\u540e\u5728single.php\u4e2d\u7684 endwhile; endif; wp_reset_query(); \u5faa\u73af\u524d\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<div class=\"codecolorer-container php railscasts\" style=\"color: #e6e1dc; margin: 0px 0px 10px; padding: 0px; border: 1px solid #9f9f9f; outline: none; font-size: 13px; line-height: 1.4em; font-family: Monaco, 'Lucida Console', monospace; overflow: auto; white-space: nowrap; background-color: #2b2b2b;\">\n<div class=\"php codecolorer\" style=\"margin: 0px; padding: 5px; border: 0px; outline: none; line-height: 1.4em;\"><span class=\"kw2\" style=\"line-height: 1.4em; color: #cc7833;\">&lt;?php<\/span>\u00a0setPostViews<span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span>get_the_ID<span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span><span class=\"sy0\" style=\"line-height: 1.4em;\">;<\/span><span class=\"sy1\" style=\"line-height: 1.4em; color: #cc7833;\">?&gt;<\/span><\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<p style=\"color: #666666; margin: 0px 0px 30px; padding: 0px; border: 0px; outline: none; font-size: 1.4em; line-height: 1.7em;\">\u6700\u540e\u5728\u4f60\u60f3\u8981\u663e\u793a\u6587\u7ae0\u6d4f\u89c8\u6b21\u6570\u7edf\u8ba1\u7684\u5730\u65b9\uff08\u4e00\u822c\u5728index.php\u3001sidebar.php\u6216single.php\u6587\u4ef6\uff09 \u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\u5373\u53ef\u3002<\/p>\n<div class=\"codecolorer-container php railscasts\" style=\"color: #e6e1dc; margin: 0px 0px 10px; padding: 0px; border: 1px solid #9f9f9f; outline: none; font-size: 13px; line-height: 1.4em; font-family: Monaco, 'Lucida Console', monospace; overflow: auto; white-space: nowrap; background-color: #2b2b2b;\">\n<div class=\"php codecolorer\" style=\"margin: 0px; padding: 5px; border: 0px; outline: none; line-height: 1.4em;\"><span class=\"kw2\" style=\"line-height: 1.4em; color: #cc7833;\">&lt;?php<\/span>\u00a0<span class=\"kw1\" style=\"line-height: 1.4em; color: #cc7833;\">echo<\/span>\u00a0getPostViews<span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span>get_the_ID<span class=\"br0\" style=\"line-height: 1.4em;\">(<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span><span class=\"br0\" style=\"line-height: 1.4em;\">)<\/span><span class=\"sy0\" style=\"line-height: 1.4em;\">;<\/span>\u00a0<span class=\"sy1\" style=\"line-height: 1.4em; color: #cc7833;\">?&gt;<\/span>\u00a0\u6b21\u6d4f\u89c8<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><ins id=\"uuhar_1402031013302\" style=\"display: block; width: 580px; height: 90px; overflow: hidden; visibility: visible;\"><span style=\"font-size: 1.4em; line-height: 1.7em; color: #464646;\"><b>\u8f6c\u8f7d\u81ea\u7f51\u7edc\uff1a<\/b><\/span><span style=\"font-size: 1.4em; line-height: 1.7em; color: #333333;\">http:\/\/www.wpbus.com.cn\/code-realization-the-<span class='wp_keywordlink_affiliate'><a href=\"http:\/\/www.wuhaibin.com\/blog\/category\/work\/wordpress\" title=\"WordPress\" rel=\"nofollow\" target=\"_blank\">WordPress<\/a><\/span>-browse-frequency-statistics.html<\/span><\/ins><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e2a\u529f\u80fd\u76f8\u4fe1\u5927\u90e8\u5206\u535a\u5ba2\u90fd\u4f1a\u7528\u5230\uff0c\u4eca\u5929\u4ecb\u7ecd\u7684\u4f7f\u7528\u63d2\u5165\u4ee3\u7801\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\uff0c\u4ee3\u7801\u76f2\u6216\u8005\u61d2\u5f97\u6298\u817e\u4ee3\u7801\u7684\u7ae5\u978b\u53ef\u4ee5\u4f7f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[30],"tags":[34],"views":4692,"_links":{"self":[{"href":"http:\/\/www.wuhaibin.com\/blog\/wp-json\/wp\/v2\/posts\/405"}],"collection":[{"href":"http:\/\/www.wuhaibin.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wuhaibin.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wuhaibin.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wuhaibin.com\/blog\/wp-json\/wp\/v2\/comments?post=405"}],"version-history":[{"count":0,"href":"http:\/\/www.wuhaibin.com\/blog\/wp-json\/wp\/v2\/posts\/405\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wuhaibin.com\/blog\/wp-json\/wp\/v2\/media?parent=405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wuhaibin.com\/blog\/wp-json\/wp\/v2\/categories?post=405"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wuhaibin.com\/blog\/wp-json\/wp\/v2\/tags?post=405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}