<\/a>\u00a0\u3001<\/p>\n\u4e3a\u4e86\u53bb\u6389\u5206\u7c7b\u94fe\u63a5\u4e2dcategory\u76ee\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528WP No category Base\u00a0\u63d2\u4ef6\u3002\u8fd8\u6709\u901a\u8fc7\u5728\u56fa\u5b9a\u94fe\u63a5\u4e2d\u7684category\u5199\u4e0a\u82f1\u6587\u7684\u53e5\u53f7\u6765\u53bb\u9664category\u7684\u65b9\u6cd5\uff0c\u672c\u7740\u80fd\u4f7f\u7528\u4ee3\u7801\u5c3d\u91cf\u4e0d\u4f7f\u7528\u63d2\u4ef6\u7684\u539f\u5219\uff0c\u6211\u4eec\u5c31\u4f7f\u7528\u4ee3\u7801\u6765\u53bb\u6389category\u3002\u590d\u5236\u4e0b\u9762\u4ee3\u7801\uff0c\u7c98\u8d34\u5230\u4f60\u7f51\u7ad9\u4f7f\u7528\u7684\u4e3b\u9898\u7684\u6a21\u677f\u51fd\u6570\u6587\u4ef6 functions.php \u6587\u4ef6\u4e2d\u5373\u53ef\uff1a<\/p>\n
\/\/\u53bb\u9664\u5206\u7c7b\u6807\u5fd7\u4ee3\u7801\r\nadd_action( 'load-themes.php', 'no_category_base_refresh_rules');\r\nadd_action('created_category', 'no_category_base_refresh_rules');\r\nadd_action('edited_category', 'no_category_base_refresh_rules');\r\nadd_action('delete_category', 'no_category_base_refresh_rules');\r\nfunction no_category_base_refresh_rules() {\r\n global $wp_rewrite;\r\n $wp_rewrite -> flush_rules();\r\n}\r\n\/\/ register_deactivation_hook(__FILE__, 'no_category_base_deactivate');\r\n\/\/ function no_category_base_deactivate() {\r\n\/\/ remove_filter('category_rewrite_rules', 'no_category_base_rewrite_rules');\r\n\/\/ \/\/ We don't want to insert our custom rules again\r\n\/\/ no_category_base_refresh_rules();\r\n\/\/ }\r\n\/\/ Remove category base\r\nadd_action('init', 'no_category_base_permastruct');\r\nfunction no_category_base_permastruct() {\r\n global $wp_rewrite, $wp_version;\r\n if (version_compare($wp_version, '3.4', '<')) {\r\n \/\/ For pre-3.4 support\r\n $wp_rewrite -> extra_permastructs['category'][0] = '%category%';\r\n } else {\r\n $wp_rewrite -> extra_permastructs['category']['struct'] = '%category%';\r\n }\r\n}\r\n\/\/ Add our custom category rewrite rules\r\nadd_filter('category_rewrite_rules', 'no_category_base_rewrite_rules');\r\nfunction no_category_base_rewrite_rules($category_rewrite) {\r\n \/\/var_dump($category_rewrite); \/\/ For Debugging\r\n $category_rewrite = array();\r\n $categories = get_categories(array('hide_empty' => false));\r\n foreach ($categories as $category) {\r\n $category_nicename = $category -> slug;\r\n if ($category -> parent == $category -> cat_ID)\/\/ recursive recursion\r\n $category -> parent = 0;\r\n elseif ($category -> parent != 0)\r\n $category_nicename = get_category_parents($category -> parent, false, '\/', true) . $category_nicename;\r\n $category_rewrite['(' . $category_nicename . ')\/(?:feed\/)?(feed|rdf|rss|rss2|atom)\/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';\r\n $category_rewrite['(' . $category_nicename . ')\/page\/?([0-9]{1,})\/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';\r\n $category_rewrite['(' . $category_nicename . ')\/?$'] = 'index.php?category_name=$matches[1]';\r\n }\r\n \/\/ Redirect support from Old Category Base\r\n global $wp_rewrite;\r\n $old_category_base = get_option('category_base') ? get_option('category_base') : 'category';\r\n $old_category_base = trim($old_category_base, '\/');\r\n $category_rewrite[$old_category_base . '\/(.*)$'] = 'index.php?category_redirect=$matches[1]';\r\n \/\/var_dump($category_rewrite); \/\/ For Debugging\r\n return $category_rewrite;\r\n}\r\n\/\/ Add 'category_redirect' query variable\r\nadd_filter('query_vars', 'no_category_base_query_vars');\r\nfunction no_category_base_query_vars($public_query_vars) {\r\n $public_query_vars[] = 'category_redirect';\r\n return $public_query_vars;\r\n}\r\n\/\/ Redirect if 'category_redirect' is set\r\nadd_filter('request', 'no_category_base_request');\r\nfunction no_category_base_request($query_vars) {\r\n \/\/print_r($query_vars); \/\/ For Debugging\r\n if (isset($query_vars['category_redirect'])) {\r\n $catlink = trailingslashit(get_option('home')) . user_trailingslashit($query_vars['category_redirect'], 'category');\r\n status_header(301);\r\n header(\"Location: $catlink\");\r\n exit();\r\n }\r\n return $query_vars;\r\n}<\/code><\/pre>\n\u8fd9\u6bb5\u53bb\u6389\u5206\u7c7b\u94fe\u63a5\u4e2dcategory\u7684\u4ee3\u7801\uff0c\u5176\u5b9e\u5c31\u662fWP No category Base \u63d2\u4ef6\u7684\u4e3b\u4f53\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u4e0d\u5b89\u88c5\u8fd9\u4e2a\u63d2\u4ef6\uff0c\u76f4\u63a5\u901a\u8fc7\u4e3b\u9898\u51fd\u6570\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002\u63d2\u4ef6\u7528\u591a\u4e86\u4f1a\u5f71\u54cd\u7f51\u7ad9\u8bbf\u95ee\u901f\u5ea6\uff0c\u7ed9\u670d\u52a1\u5668\u5e26\u6765\u538b\u529b\u3002\u4e0d\u7ba1\u5b89\u88c5\u63d2\u4ef6\u6216\u8005\u7528\u4ee3\u7801\u6709\u53ef\u80fd\u4f1a\u51fa\u73b0404\u9875\u9762\uff0c\u53ef\u80fd\u662f\u56e0\u4e3a%post_id%.html\uff08\u672c\u7ad9\u8bbe\u7f6e\u7684\u56fa\u5b9a\u94fe\u63a5\uff09\u7684\u4f2a\u9759\u6001\u5931\u6548\u3002\u53ea\u8981\u767b\u5f55\u540e\u53f0\u2192\u8bbe\u7f6e\u2192\u56fa\u5b9a\u94fe\u63a5\u8bbe\u7f6e\u9875\u9762\uff0c\u968f\u610f\u6539\u4e00\u4e0b\u56fa\u5b9a\u94fe\u63a5\u683c\u5f0f\uff0c\u7136\u540e\u518d\u6539\u56de\u81ea\u5df1\u6b63\u5e38\u7528\u7684\u7b26\u5408\u7f51\u7ad9\u4f2a\u9759\u6001\u7684\u56fa\u5b9a\u94fe\u63a5\u683c\u5f0f\uff0c\u4e0d\u884c\u5c31\u591a\u6539\u51e0\u6b21\u3002\u5207\u8bb0\u8981\u628a\u6240\u6709\u7f13\u5b58\u6e05\u9664\u540e\u5c1d\u8bd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u6211\u4eec\u505a\u597d\u4f2a\u9759\u6001\u540e\uff0c\u53d1\u73b0\u5728\u5206\u7c7b\u94fe\u63a5\u4e2d\u4f1a\u51fa\u73b0\u4e00\u4e2a\/category\/\u76ee\u5f55\u3002\u5982\u4e0b\u56fe\u3002 \u00a0\u3001 \u4e3a\u4e86\u53bb\u6389\u5206\u7c7b\u94fe\u63a5\u4e2dcat […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[914,5,913,912],"class_list":["post-2744","post","type-post","status-publish","format-standard","hentry","category-wljs","tag-category","tag-wordpress","tag-913","tag-912"],"_links":{"self":[{"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/posts\/2744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/comments?post=2744"}],"version-history":[{"count":0,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/posts\/2744\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/media?parent=2744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/categories?post=2744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/tags?post=2744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}