{"id":4303,"date":"2021-01-18T10:24:51","date_gmt":"2021-01-18T02:24:51","guid":{"rendered":"https:\/\/www.baishitou.cn\/?p=4303"},"modified":"2021-01-18T10:58:09","modified_gmt":"2021-01-18T02:58:09","slug":"wordpress%e7%ab%99%e5%86%85%e6%90%9c%e7%b4%a2%e8%b7%b3%e8%bd%ac%e5%88%b0%e7%99%be%e5%ba%a6%e6%90%9c%e7%b4%a2%ef%bc%8c%e6%90%9c%e7%b4%a2%e4%b8%ad%e6%96%87%e6%96%87%e5%ad%97%e8%a2%ab%e8%bd%ac%e4%b9%89","status":"publish","type":"post","link":"https:\/\/www.baishitou.cn\/4303.html","title":{"rendered":"wordpress\u7ad9\u5185\u641c\u7d22\u8df3\u8f6c\u5230\u767e\u5ea6\u641c\u7d22\uff0c\u641c\u7d22\u4e2d\u6587\u6587\u5b57\u88ab\u8f6c\u4e49\u4e71\u7801\u7684\u89e3\u51b3\u65b9\u6cd5"},"content":{"rendered":"
\u6700\u8fd1\uff0c\u767d\u77f3\u5934\u535a\u5ba2\u88ab\u5237\u4e86\u4e00\u4e9b\u4e71\u4e03\u516b\u7cdf\u7684\u8bcd\uff0c\u5e76\u4e14\u88ab\u767e\u5ea6\u6536\u5f55\u4e86\uff0c\u5982\u4e0b\u56fe\uff0c\u4ee5\u524d\u6536\u5f55\u51e0\u5343\u4e2a\u9875\u9762\uff0c\u88ab\u5237\u540e\uff0c\u73b0\u5728\u6536\u5f559\u4e07\u591a\u4e2a\u9875\u9762\uff0c\u4e25\u91cd\u5f71\u54cd\u4e86\u672c\u7ad9\u7684\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n
<\/p>\n \u8fd9\u6837\u867d\u7136\u6211\u7684\u7f51\u7ad9\u6ca1\u6709\u8fd9\u4e2a\u5185\u5bb9\uff0c\u4f46\u8bbf\u95ee\u8fc7\u6765\u90fd\u4f1a\u6709\u4e0b\u9762\u663e\u793a\uff1a<\/p>\n \u6700\u5f00\u59cb\u6211\u60f3\u901a\u8fc7301\u91cd\u5b9a\u5411\u6240\u6709\u8bbf\u95ee\u5730\u5740\u91cc\u9762\u6709\/?=\u7684\u6765\u6e90\u641c\u7d22\u81ea\u52a8\u8f6c\u5411\u7f51\u7ad9\u9996\u9875\uff0c\u8fd9\u6837\u5c31\u4e0d\u4f1a\u770b\u5230\u8fd9\u79cd\u60c5\u51b5\uff0c\u5728\u5b9d\u5854\u9762\u677f\u8bd5\u4e86\u597d\u4e45\uff0c\u6ca1\u6709\u6210\u529f\u3002\u53ea\u80fd\u901a\u8fc7\u4fee\u6539\u6587\u4ef6\u5b9e\u73b0\u4e86\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u5728\u5f53\u524d\u4e3b\u9898\u6587\u4ef6\u5939\u91cc\u9762\u7684functions.php\u52a0\u5165\u4e0b\u9762\u4ee3\u7801\uff0c\u7136\u540e\u4fdd\u5b58\u3002<\/p>\n \u8fd9\u6837\uff0c\u522b\u4eba\u70b9\u51fb\u8fd9\u6837\u7684\u5783\u573e\u94fe\u63a5\u7684\u8bdd\uff0c\u5c31\u76f4\u63a5\u8df3\u8f6c\u5230\u672c\u7ad9\u9996\u9875\u4e86\uff0c\u5982\u679c\u662f\u641c\u7d22\u6b63\u5e38\u5173\u952e\u5b57\uff0c\u5219\u663e\u793a\u6b63\u5e38\u641c\u7d22\u9875\u3002<\/p>\n \u8fd8\u6709\u8fd9\u4e0b\u9762\u8fd9\u79cd\u65b9\u6cd5\uff0c\u65e0\u8bba\u6709\u6ca1\u6709\u641c\u7d22\u7ed3\u679c\u90fd\u81ea\u52a8\u8df3\u8f6c\u5230\u9996\u9875\uff08\u6b64\u65b9\u6cd5\u6ca1\u6d4b\u8bd5\u8fc7\uff09<\/p>\n <\/p>\n \u7b2c\u4e09\u79cd\u65b9\u6cd5\u5c31\u662f\u628awordpress\u7ad9\u5185\u641c\u7d22\u76f4\u63a5\u66ff\u6362\u6210\u767e\u5ea6\u641c\u7d22\u3002<\/p>\n \u4ee3\u7801\uff1a<\/p>\n \u6548\u679c\u5982\u4e0b\uff1a<\/p>\n \u522b\u4eba\u70b9\u51fb\u6536\u5f55\u7684\u5783\u573e\u94fe\u63a5\u5c31\u662f\u8fd9\u6837\u7684\u3002<\/p>\n \u6700\u5f00\u59cb\u6d4b\u8bd5\u65f6\uff0c\u641c\u7d22\u82f1\u6587\u6216\u8005\u6570\u5b57\u7684\u8bdd\uff0c\u641c\u7d22\u7ed3\u679c\u662f\u6b63\u5e38\u7684\uff0c\u4f46\u641c\u7d22\u4e2d\u6587\u7684\u8bdd\uff0c\u5728\u767e\u5ea6\u641c\u7d22\u7684\u4e2d\u6587\u88ab\u8f6c\u4e49\u4e86\uff0c\u4e5f\u5c31\u662f\u663e\u793a\u4e71\u7801\u3002\u5982\u4e0b\u56fe<\/p>\n <\/p>\n \u627e\u5230\u597d\u4e45\uff0c\u624d\u627e\u5230\u89e3\u51b3\u7684\u65b9\u6cd5\uff0c\u627e\u5230search\u7684\u76f8\u5173\u4ee3\u7801\uff08\u4e00\u822c\u5728header.php\uff09\uff0c\u628a\u91cc\u9762\u7684<\/p>\n \u4fee\u6539\u4e3a\uff1a<\/p>\n \u5982\u679c\u641c\u7d22\u7ed3\u679c\u524d\u9762\u591a\u4e2a\/\u7684\u8bdd\uff0c\u76f4\u63a5\u628a\u4e0a\u9762\u7684\/\u53bb\u6389\u5c31\u884c\u4e86\u3002<\/p>\n <\/p>\n \u53c2\u8003\u6587\u7ae0\uff1a<\/p>\n<\/a><\/p>\n
<\/a><\/p>\n
\/* WordPress\u641c\u7d22\u7ed3\u679c\u4e2d\u65e0\u5185\u5bb9\u65f6\u81ea\u52a8\u8df3\u8f6c\u5230\u7f51\u7ad9\u9996\u9875 *\/\r\nadd_action('template_redirect', 'redirect_single_post');\r\nfunction redirect_single_post() {\r\n if (is_search()) {\r\n global $wp_query;\r\n if ($wp_query->post_count == 0 && $wp_query->max_num_pages == 0) {\r\n wp_redirect( home_url() );\r\n exit;\r\n }\r\n }\r\n}<\/code><\/pre>\n
\/\/\u7981\u7528WordPress\u524d\u53f0\u641c\u7d22\u529f\u80fd\r\nfunction disable_search( $query, $error = true ) {\r\n\tif (is_search() && !is_admin()) {\r\n\t\t$query->is_search = false;\r\n\t\t$query->query_vars['s'] = false;\r\n\t\t$query->query['s'] = false;\r\n\t\tif ( $error == true )\r\n\t\t\/\/ \u6267\u884c\u641c\u7d22\u540e\u663e\u793a\u7684\u9519\u8bef\u9875\u9762\r\n\t\t $query->is_home = true; \/\/\u8df3\u8f6c\u5230\u9996\u9875\r\n\t\t\/\/ $query->is_404 = true;\/\/\u8df3\u8f6c\u5230404\u9875\r\n\t}\r\n}\r\nadd_action( 'parse_query', 'disable_search' );\r\nadd_filter( 'get_search_form', create_function( '$a', \"return null;\" ) );<\/code><\/pre>\n
\/\/wordpress\u7ad9\u5185\u641c\u7d22\u66ff\u6362\u4e3a\u767e\u5ea6\u641c\u7d22\r\nfunction wp_use_baidu_search( $wp_query ) {\r\n $s = ''; \r\n if (isset($wp_query->query_vars['s'])) {\r\n $s = trim($wp_query->query_vars['s']);\r\n }\r\n if (!$s) { \/\/ \u7a7a\u641c\u7d22 \u4e0d\u8fdb\u884c\u8df3\u8f6c\r\n return;\r\n }\r\n \/\/ \u83b7\u53d6\u5f53\u524d\u7f51\u7ad9\u57df\u540d\r\n $host = strtolower($_SERVER['HTTP_HOST']); \r\n \/\/ \u4f7f\u7528 baidu \r\n $search_engine = 'https:\/\/www.baidu.com\/s?ie=UTF-8&wd=';\r\n $query = urlencode($s . ' site:' . $host);\r\n \/\/ \u8fdb\u884c\u8df3 \u8f6c\r\n wp_redirect($search_engine . $query); \r\n \/\/ \u4e0d\u518d\u7ee7\u7eed\r\n exit;\r\n} \r\n\/\/ \u52a0\u5165 \u66ff\u6362\u5904\u7406\r\nadd_action('parse_query', 'wp_use_baidu_search');<\/code><\/pre>\n
<\/a><\/p>\n
<\/a><\/p>\n
<\/a><\/p>\n
<?php echo home_url('\/search\/<\/span>'); ?><\/code><\/pre>\n
<?php echo home_url('\/?s=<\/span>'); ?><\/code><\/pre>\n