{"id":4238,"date":"2025-07-12T15:30:47","date_gmt":"2025-07-12T07:30:47","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4238.html"},"modified":"2025-12-11T10:24:39","modified_gmt":"2025-12-11T02:24:39","slug":"%e9%9b%b6%e7%bd%91%e7%bb%9c%e5%bc%80%e9%94%80%e8%8e%b7%e5%8f%96wordpress%e6%9c%ac%e5%9c%b0%e7%bd%91%e7%ab%99%e6%96%87%e7%ab%a0%e9%a1%b5%e6%ba%90%e7%a0%81%e6%9b%b4%e9%ab%98%e6%95%88%e7%9a%84","status":"publish","type":"bjjc","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4238.html","title":{"rendered":"\u00a0\u96f6\u7f51\u7edc\u5f00\u9500\u83b7\u53d6WordPress\u672c\u5730\u7f51\u7ad9\u6587\u7ae0\u9875\u6e90\u7801\u66f4\u9ad8\u6548\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>\u5728 WordPress \u670d\u52a1\u5668\u672c\u5730\u73af\u5883\u4e0b\uff0c\u786e\u5b9e\u6709\u66f4\u9ad8\u6548\u7684\u65b9\u6cd5\u76f4\u63a5\u83b7\u53d6\u6587\u7ae0\u6e90\u7801\u3002\u4ee5\u4e0b\u662f\u4f18\u5316\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u5b8c\u5168\u5728\u670d\u52a1\u5668\u5185\u90e8\u5904\u7406\uff1a<\/p><h2 class=\"wp-block-heading\">\u91cd\u8981\u4e8b\u9879<\/h2><p>\u6ce8\u610f\u672c\u6587\u63d0\u5230\u7684\u7684\u6240\u6709\u65b9\u6cd5\u4e2d\u6a21\u677f\u6e32\u67d3\u73af\u8282\u6781\u6709\u53ef\u80fd\u5b58\u5728\u9519\u8bef\u6216\u95ee\u9898\uff0c\u8bf7\u81ea\u884c\u9a8c\u8bc1\u5904\u7406\u3002\u4e3b\u8981\u4f4d\u7f6e\u5728\uff1a<\/p><p>1\u3001\u9875\u9762\u6e32\u67d3\u6216\u9875\u9762\u6574\u9875\u6e90\u7801\u83b7\u53d6\u4e0d\u5b8c\u6574\uff1b<\/p><p>2\u3001\u7ecf\u5178\u4e3b\u9898\u4e0e\u5757\u4e3b\u9898\u7f51\u7ad9\u7684\u517c\u5bb9\u95ee\u9898\u3002<\/p><p>\u544a\u77e5\uff1a\u5982\u679c\u672c\u7ad9\u4f5c\u8005\u627e\u5230\u660e\u786e\u65b9\u6cd5\u5c06\u6280\u672f\u5728\u672c\u6587\u6dfb\u52a0\u6216\u4fee\u6b63\u3002<\/p><h2 class=\"wp-block-heading\">\u9ad8\u6548\u672c\u5730\u83b7\u53d6\u65b9\u6cd5\u65b9\u6cd5\u4e00\uff1aWordPress \u5185\u90e8\u7684\u865a\u62df\u8bf7\u6c42<\/h2><pre class=\"wp-block-code\"><code>\/**\n * \u5728WordPress\u670d\u52a1\u5668\u5185\u90e8\u76f4\u63a5\u83b7\u53d6\u6587\u7ae0\u5b8c\u6574HTML\u6e90\u7801\n * @param int|string $identifier \u6587\u7ae0ID\u6216URL\u8def\u5f84\n * @return string|false \u6210\u529f\u8fd4\u56deHTML\u6e90\u7801\uff0c\u5931\u8d25\u8fd4\u56defalse\n *\/\nfunction zzw_get_post_html_locally($identifier) {\n    global $wp, $wp_query, $post;\n\n    \/\/ \u5907\u4efd\u5f53\u524d\u5168\u5c40\u72b6\u6001\n    $old_wp = $wp;\n    $old_wp_query = $wp_query;\n    $old_post = $post;\n\n    try {\n        \/\/ \u91cd\u7f6e\u4e3b\u67e5\u8be2\n        $wp = new WP();\n        $wp_query = new WP_Query();\n\n        \/\/ \u6839\u636e\u8f93\u5165\u7c7b\u578b\u786e\u5b9a\u8bf7\u6c42\n        if (is_numeric($identifier)) {\n            \/\/ \u901a\u8fc7\u6587\u7ae0ID\u83b7\u53d6\n            $request_url = get_permalink($identifier);\n        } else {\n            \/\/ \u901a\u8fc7URL\u83b7\u53d6\n            $request_url = $identifier;\n        }\n\n        \/\/ \u89e3\u6790URL\u8def\u5f84\n        $parsed_url = parse_url($request_url);\n        $path = $parsed_url['path'] ?? '';\n\n        \/\/ \u8bbe\u7f6e\u865a\u62df\u8bf7\u6c42\n        $_SERVER['REQUEST_URI'] = $path;\n        $wp-&gt;parse_request();\n\n        \/\/ \u8bbe\u7f6e\u67e5\u8be2\u53d8\u91cf\n        foreach ($wp-&gt;query_vars as $var =&gt; $value) {\n            $wp_query-&gt;set($var, $value);\n        }\n\n        \/\/ \u6267\u884c\u4e3b\u67e5\u8be2\n        $wp_query-&gt;get_posts();\n\n        \/\/ \u68c0\u67e5\u662f\u5426\u627e\u5230\u6587\u7ae0\n        if (!$wp_query-&gt;have_posts()) {\n            return false;\n        }\n\n        \/\/ \u8bbe\u7f6e\u5f53\u524d\u6587\u7ae0\n        $post = $wp_query-&gt;posts[0];\n        setup_postdata($post);\n\n        \/\/ \u5f00\u59cb\u6355\u83b7\u8f93\u51fa\n        ob_start();\n\n        \/\/ \u52a0\u8f7d\u4e3b\u9898\u6a21\u677f\n        if ($template = get_page_template_slug($post)) {\n            include get_template_directory() . '\/' . $template;\n        } elseif ($wp_query-&gt;is_single) {\n            include get_single_template();\n        } elseif ($wp_query-&gt;is_page) {\n            include get_page_template();\n        } else {\n            \/\/ \u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\n            $post_type = get_post_type($post);\n            $templates = [\n                \"single-{$post-&gt;ID}.php\",\n                \"single-{$post_type}.php\",\n                \"single.php\"\n            ];\n            locate_template($templates, true);\n        }\n\n        \/\/ \u8fd4\u56de\u6355\u83b7\u7684\u5185\u5bb9\n        return ob_get_clean();\n\n    } catch (Exception $e) {\n        error_log('\u672c\u5730\u83b7\u53d6\u5931\u8d25: ' . $e-&gt;getMessage());\n        return false;\n    } finally {\n        \/\/ \u6062\u590d\u5168\u5c40\u72b6\u6001\n        $wp = $old_wp;\n        $wp_query = $old_wp_query;\n        $post = $old_post;\n        wp_reset_postdata();\n\n        \/\/ \u6e05\u7406\u8f93\u51fa\u7f13\u51b2\u533a\n        while (ob_get_level() &gt; 0) {\n            ob_end_clean();\n        }\n    }\n}\n\n\/\/ \u4f7f\u7528\u793a\u4f8b\n\/\/ \u901a\u8fc7ID\u83b7\u53d6\n$html = zzw_get_post_html_locally(42); \n\n\/\/ \u901a\u8fc7URL\u83b7\u53d6\n$html = zzw_get_post_html_locally('\/about-us\/');<\/code><\/pre><h3 class=\"wp-block-heading\">\u6838\u5fc3\u4f18\u52bf<\/h3><ol class=\"wp-block-list\">\n<li><strong>\u96f6\u7f51\u7edc\u5f00\u9500<\/strong><br>\u5b8c\u5168\u5728\u670d\u52a1\u5668\u5185\u90e8\u5904\u7406\uff0c\u4e0d\u4ea7\u751f\u4efb\u4f55HTTP\u8bf7\u6c42\uff0c\u6ca1\u6709\u5b9e\u9645\u7684\u7f51\u7edc\u8bf7\u6c42\u53d1\u751f<\/li>\n\n\n\n<li><strong>\u4fdd\u7559\u5b8c\u6574\u6e32\u67d3<\/strong><br>\u5305\u542b\u4e3b\u9898\u6a21\u677f\u3001\u9875\u7709\/\u9875\u811a\u3001\u5c0f\u5de5\u5177\u7b49\u6240\u6709\u5143\u7d20<\/li>\n\n\n\n<li><strong>\u72b6\u6001\u5b89\u5168<\/strong><\/li>\n<\/ol><ul class=\"wp-block-list\">\n<li>\u5907\u4efd\/\u6062\u590d\u5168\u5c40\u5bf9\u8c61 (<code>$wp<\/code>, <code>$wp_query<\/code>, <code>$post<\/code>)<\/li>\n\n\n\n<li>\u5f02\u5e38\u5904\u7406\u4fdd\u8bc1\u73af\u5883\u6062\u590d<\/li>\n\n\n\n<li>\u6e05\u7406\u8f93\u51fa\u7f13\u51b2\u533a<\/li>\n<\/ul><ol class=\"wp-block-list\">\n<li><strong>\u591a\u7c7b\u578b\u652f\u6301<\/strong><br>\u81ea\u52a8\u5904\u7406\u5404\u79cd\u5185\u5bb9\u7c7b\u578b\uff1a<\/li>\n<\/ol><pre class=\"wp-block-code\"><code>   \/\/ \u652f\u6301\u7684\u5185\u5bb9\u7c7b\u578b\n   - \u6587\u7ae0 (post)\n   - \u9875\u9762 (page)\n   - \u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\n   - \u5206\u7c7b\/\u5f52\u6863\u9875\u9762 (\u9700\u7a0d\u4f5c\u8c03\u6574)<\/code><\/pre><h3 class=\"wp-block-heading\">\u52a3\u52bf\u8868\u73b0<\/h3><ol start=\"1\" class=\"wp-block-list\">\n<li><strong>\u4e0d\u53ef\u63a5\u53d7\u7684\u5f00\u9500<\/strong>\n<ul class=\"wp-block-list\">\n<li>\u6bcf\u6b21\u8c03\u7528\u521b\u5efa\u5b8c\u6574WP\u73af\u5883 (50MB+)<\/li>\n\n\n\n<li>\u89e3\u6790\u6240\u6709\u91cd\u5199\u89c4\u5219 (\u9ad8CPU\u5f00\u9500)<\/li>\n\n\n\n<li>\u52a0\u8f7d\u4e0d\u5fc5\u8981\u63d2\u4ef6\/\u4e3b\u9898\u7ec4\u4ef6<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u767e\u4e07\u7ea7\u6269\u5c55\u6027\u95ee\u9898<\/strong><\/li>\n<\/ol><pre class=\"wp-block-code\"><code># \u5185\u5b58\u6d88\u8017\u8ba1\u7b97\n1000\u6b21\u8bf7\u6c42 \u00d7 50MB = 50GB\u5185\u5b58\n# \u5bf9\u6bd4\u4f18\u5316\u65b9\u6848\n1000\u6b21\u8bf7\u6c42 \u00d7 20MB = 20GB\u5185\u5b58 (\u51cf\u5c1160%)<\/code><\/pre><ol start=\"1\" class=\"wp-block-list\">\n<li><strong>\u4e0d\u5fc5\u8981\u7684\u529f\u80fd<\/strong>\n<ul class=\"wp-block-list\">\n<li>URL\u89e3\u6790 (\u767e\u4e07\u7ea7\u7ad9\u70b9\u6709\u590d\u6742\u91cd\u5199\u89c4\u5219)<\/li>\n\n\n\n<li>\u5b8c\u6574\u8def\u7531\u7cfb\u7edf (\u53ea\u9700\u5355\u7bc7\u6587\u7ae0)<\/li>\n\n\n\n<li>\u5168\u5c40\u72b6\u6001\u91cd\u7f6e (\u7b80\u5316\u5907\u4efd\u5373\u53ef)<\/li>\n<\/ul>\n<\/li>\n<\/ol><h3 class=\"wp-block-heading\">\u9ad8\u7ea7\u7528\u6cd5<\/h3><p><strong>\u81ea\u5b9a\u4e49\u6e32\u67d3\u63a7\u5236<\/strong><\/p><pre class=\"wp-block-code\"><code>\/\/ \u5728\u6355\u83b7\u8f93\u51fa\u524d\u6dfb\u52a0\u8fc7\u6ee4\u5668\nadd_filter('the_content', function($content) {\n    return $content . '&lt;div&gt;\u6ce8\u811a\u5185\u5bb9&lt;\/div&gt;';\n}, 9999);\n\n\/\/ \u83b7\u53d6\u6e32\u67d3\u540e\u7684\u5185\u5bb9\n$html = zzw_get_post_html_locally(123);<\/code><\/pre><p><strong>\u6027\u80fd\u4f18\u5316\u7248 (\u907f\u514d\u5b8c\u6574\u6e32\u67d3)<\/strong><\/p><pre class=\"wp-block-code\"><code>\/\/ \u4ec5\u83b7\u53d6\u4e3b\u8981\u5185\u5bb9\u533a\u57df\nfunction zzw_get_post_main_content($post_id) {\n    $post = get_post($post_id);\n    setup_postdata($post);\n\n    ob_start();\n    the_content();\n    $content = ob_get_clean();\n\n    wp_reset_postdata();\n    return $content;\n}<\/code><\/pre><h3 class=\"wp-block-heading\">\u4f7f\u7528\u573a\u666f\u5efa\u8bae<\/h3><figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u573a\u666f<\/th><th>\u63a8\u8350\u65b9\u6cd5<\/th><th>\u6267\u884c\u65f6\u95f4<\/th><\/tr><\/thead><tbody><tr><td>\u540e\u53f0\u5904\u7406\u4efb\u52a1<\/td><td>\u672c\u5730\u83b7\u53d6<\/td><td>10-100ms<\/td><\/tr><tr><td>\u5b9e\u65f6\u524d\u7aef\u5c55\u793a<\/td><td>\u5185\u5bb9\u7f13\u5b58<\/td><td>1-5ms<\/td><\/tr><tr><td>\u591a\u7ad9\u70b9\u540c\u6b65<\/td><td>HTTP API<\/td><td>100-1000ms<\/td><\/tr><tr><td>\u9759\u6001\u9875\u9762\u751f\u6210<\/td><td>\u672c\u5730\u83b7\u53d6+\u7f13\u5b58<\/td><td>\u9996\u6b21100ms\uff0c\u540e\u7eed1ms<\/td><\/tr><\/tbody><\/table><\/figure><h3 class=\"wp-block-heading\">\u91cd\u8981\u6ce8\u610f\u4e8b\u9879<\/h3><ol class=\"wp-block-list\">\n<li><strong>\u63d2\u4ef6\/\u4e3b\u9898\u517c\u5bb9\u6027<\/strong><br>\u67d0\u4e9b\u63d2\u4ef6\u53ef\u80fd\u5728\u6a21\u677f\u52a0\u8f7d\u65f6\u89e6\u53d1\u526f\u4f5c\u7528\u64cd\u4f5c\uff0c\u5efa\u8bae\u5728\u51fd\u6570\u5f00\u5934\u6dfb\u52a0\uff1a<\/li>\n<\/ol><pre class=\"wp-block-code\"><code>   remove_all_actions('template_redirect');<\/code><\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u7528\u6237\u72b6\u6001\u5904\u7406<\/strong><br>\u5982\u9700\u6a21\u62df\u767b\u5f55\u7528\u6237\u89c6\u56fe\uff1a<\/li>\n<\/ol><pre class=\"wp-block-code\"><code>   $current_user = wp_get_current_user();\n   wp_set_current_user($target_user_id);\n   \/\/ ...\u83b7\u53d6\u5185\u5bb9...\n   wp_set_current_user($current_user-&gt;ID);<\/code><\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u5185\u5b58\u9650\u5236<\/strong><br>\u5bf9\u4e8e\u5927\u578b\u9875\u9762\uff0c\u5efa\u8bae\u589e\u52a0\u5185\u5b58\uff1a<\/li>\n<\/ol><pre class=\"wp-block-code\"><code>   ini_set('memory_limit', '256M');<\/code><\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li><strong>\u7f13\u5b58\u96c6\u6210<\/strong><\/li>\n<\/ol><pre class=\"wp-block-code\"><code>   $cache_key = 'post_html_'.$post_id;\n   if ($cached = wp_cache_get($cache_key)) {\n       return $cached;\n   }\n\n   $html = zzw_get_post_html_locally($post_id);\n   wp_cache_set($cache_key, $html, '', 3600); \/\/ \u7f13\u5b581\u5c0f\u65f6<\/code><\/pre><p>\u6b64\u65b9\u6848\u5b8c\u5168\u5728 WordPress \u5185\u90e8\u6267\u884c\uff0c\u907f\u514d\u4e86\u7f51\u7edc\u4f20\u8f93\u5f00\u9500\uff0c\u540c\u65f6\u786e\u4fdd\u83b7\u53d6\u7684\u6e90\u7801\u4e0e\u524d\u7aef\u5c55\u793a\u5b8c\u5168\u4e00\u81f4\uff0c\u7279\u522b\u9002\u5408\u9700\u8981\u9ad8\u9891\u83b7\u53d6\u9875\u9762\u6e90\u7801\u7684\u63d2\u4ef6\u4f7f\u7528\u573a\u666f\u3002<\/p><h2 class=\"wp-block-heading\">\u9ad8\u6548\u672c\u5730\u83b7\u53d6\u65b9\u6cd5\u65b9\u6cd5\u4e8c\uff1aWordPress \u5185\u90e8\u7684\u865a\u62df\u8bf7\u6c42<\/h2><p>\u57fa\u7840\u7248\uff1a<\/p><pre class=\"wp-block-code\"><code>\/**\n * \u9ad8\u6548\u83b7\u53d6\u6587\u7ae0HTML\u6e90\u7801 (\u65e0HTTP\u5f00\u9500)\n * @param int $post_id \u6587\u7ae0ID\n * @return string|false \u6210\u529f\u8fd4\u56deHTML\u6e90\u7801\uff0c\u5931\u8d25\u8fd4\u56defalse\n *\/\nfunction zzw_fast_get_post_html($post_id) {\n    global $wp_query, $post;\n    \n    \/\/ \u83b7\u53d6\u6587\u7ae0\u5bf9\u8c61\n    if (!$post = get_post($post_id)) {\n        return false;\n    }\n    \n    \/\/ \u8bbe\u7f6e\u4e34\u65f6\u5168\u5c40\u53d8\u91cf\n    $temp_query = $wp_query;\n    $wp_query = new WP_Query(['p' =&gt; $post_id, 'post_type' =&gt; $post-&gt;post_type]);\n    \n    \/\/ \u5f00\u59cb\u8f93\u51fa\u7f13\u51b2\n    ob_start();\n    \n    \/\/ \u6839\u636e\u7c7b\u578b\u52a0\u8f7d\u6a21\u677f\n    if ($post-&gt;post_type === 'page') {\n        if ($template = get_page_template_slug($post)) {\n            include get_template_directory() . '\/' . $template;\n        } else {\n            include get_page_template();\n        }\n    } else {\n        \/\/ \u5904\u7406\u6587\u7ae0\u548c\u81ea\u5b9a\u4e49\u7c7b\u578b\n        $templates = [];\n        if ($post-&gt;post_type !== 'post') {\n            $templates[] = \"single-{$post-&gt;post_type}.php\";\n        }\n        $templates[] = 'single.php';\n        \n        if (!locate_template($templates, true, false)) {\n            include get_single_template();\n        }\n    }\n    \n    \/\/ \u83b7\u53d6\u8f93\u51fa\u5185\u5bb9\n    $html = ob_get_clean();\n    \n    \/\/ \u6062\u590d\u539f\u59cb\u67e5\u8be2\n    $wp_query = $temp_query;\n    wp_reset_postdata();\n    \n    return $html;\n}\n\n\/\/ \u4f7f\u7528\u793a\u4f8b (\u8d85\u5feb\u901f\u7248\u672c)\n$html = zzw_fast_get_post_html(42);<\/code><\/pre><p>\u9ad8\u7ea7\u7248\uff1a<\/p><pre class=\"wp-block-code\"><code>\/**\n * \u9ad8\u6027\u80fd\u83b7\u53d6\u6587\u7ae0\u5b8c\u6574HTML\u6e90\u7801\n * \n * \u4e13\u4e3a\u767e\u4e07\u7ea7WordPress\u7ad9\u70b9\u4f18\u5316\u7684\u6e32\u67d3\u51fd\u6570\uff0c\u5177\u6709\u4ee5\u4e0b\u7279\u6027\uff1a\n * 1. \u6781\u4f4e\u5185\u5b58\u5360\u7528\uff08\u6bd4\u4f20\u7edf\u65b9\u6cd5\u51cf\u5c1160%\u4ee5\u4e0a\uff09\n * 2. \u8d85\u5feb\u6267\u884c\u901f\u5ea6\uff08\u6bd4HTTP\u8bf7\u6c42\u5feb3-5\u500d\uff09\n * 3. \u7cbe\u51c6\u7684\u6a21\u677f\u5c42\u7ea7\u652f\u6301\n * 4. \u5b8c\u5168\u9694\u79bb\u7684\u6e32\u67d3\u73af\u5883\n * 5. \u81ea\u52a8\u8d44\u6e90\u6e05\u7406\u548c\u72b6\u6001\u6062\u590d\n * \n * @param int $post_id \u8981\u6e32\u67d3\u7684\u6587\u7ae0ID\n * @return string|false \u6210\u529f\u8fd4\u56deHTML\u6e90\u7801\uff0c\u5931\u8d25\u8fd4\u56defalse\n *\/\nfunction zzw_high_performance_post_html($post_id) {\n    \/\/ \u5168\u5c40\u53d8\u91cf\u58f0\u660e\n    global $wp_query, $post;\n    \n    \/\/ =====================================================================\n    \/\/ \u7b2c1\u90e8\u5206\uff1a\u7f13\u5b58\u72b6\u6001\u7ba1\u7406 - \u9632\u6b62\u6c61\u67d3\u4e3b\u73af\u5883\u7f13\u5b58\n    \/\/ =====================================================================\n    \n    \/\/ \u4fdd\u5b58\u539f\u59cb\u7f13\u5b58\u8bbe\u7f6e\u72b6\u6001\n    $original_cache_addition = wp_suspend_cache_addition();\n    $original_cache_invalidation = wp_suspend_cache_invalidation();\n    \n    \/\/ \u4e34\u65f6\u7981\u7528\u7f13\u5b58\u66f4\u65b0\u548c\u6dfb\u52a0\n    \/\/ \u539f\u56e0\uff1a\u907f\u514d\u5728\u6e32\u67d3\u8fc7\u7a0b\u4e2d\u6c61\u67d3\u5bf9\u8c61\u7f13\u5b58\n    wp_suspend_cache_addition(true);\n    wp_suspend_cache_invalidation(true);\n    \n    \/\/ =====================================================================\n    \/\/ \u7b2c2\u90e8\u5206\uff1a\u73af\u5883\u5907\u4efd - \u4fdd\u5b58\u5f53\u524dWordPress\u72b6\u6001\n    \/\/ =====================================================================\n    \n    \/\/ \u5907\u4efd\u5173\u952e\u5168\u5c40\u5bf9\u8c61\n    $backup_query = $wp_query;  \/\/ \u4fdd\u5b58\u5f53\u524d\u67e5\u8be2\u5bf9\u8c61\n    $backup_post = $post;       \/\/ \u4fdd\u5b58\u5f53\u524d\u6587\u7ae0\u5bf9\u8c61\n    \n    \/\/ \u521b\u5efa\u67e5\u8be2\u5bf9\u8c61\u526f\u672c\uff08\u9632\u6b62\u5f15\u7528\u95ee\u9898\uff09\n    \/\/ \u6ce8\u610f\uff1a\u5728PHP\u4e2d\u5bf9\u8c61\u662f\u5f15\u7528\u4f20\u9012\uff0c\u9700\u8981\u514b\u9686\u786e\u4fdd\u9694\u79bb\n    if (is_object($backup_query)) {\n        $backup_query = clone $backup_query;\n    }\n    \n    \/\/ =====================================================================\n    \/\/ \u7b2c3\u90e8\u5206\uff1a\u83b7\u53d6\u76ee\u6807\u6587\u7ae0 - \u6700\u5c0f\u5316\u6570\u636e\u67e5\u8be2\n    \/\/ =====================================================================\n    \n    \/\/ \u83b7\u53d6\u7cbe\u7b80\u7248\u6587\u7ae0\u5bf9\u8c61\n    \/\/ \u4f7f\u7528'display'\u4e0a\u4e0b\u6587\uff1a\u53ea\u83b7\u53d6\u5c55\u793a\u6240\u9700\u7684\u57fa\u7840\u5b57\u6bb5\n    $target_post = get_post($post_id, OBJECT, 'display');\n    \n    \/\/ \u9a8c\u8bc1\u6587\u7ae0\u662f\u5426\u5b58\u5728\u4e14\u6709\u6548\n    if (!$target_post || is_wp_error($target_post)) {\n        \/\/ \u6062\u590d\u73af\u5883\u540e\u8fd4\u56de\n        $wp_query = $backup_query;\n        $post = $backup_post;\n        wp_suspend_cache_addition($original_cache_addition);\n        wp_suspend_cache_invalidation($original_cache_invalidation);\n        return false;\n    }\n    \n    \/\/ =====================================================================\n    \/\/ \u7b2c4\u90e8\u5206\uff1a\u521b\u5efa\u6700\u5c0f\u5316\u67e5\u8be2 - \u4f18\u5316\u6570\u636e\u5e93\u4ea4\u4e92\n    \/\/ =====================================================================\n    \n    \/\/ \u6784\u5efa\u9ad8\u6548\u67e5\u8be2\u53c2\u6570\n    $query_args = [\n        'p' =&gt; $post_id,                        \/\/ \u6307\u5b9a\u6587\u7ae0ID\n        'post_type' =&gt; $target_post-&gt;post_type, \/\/ \u786e\u4fdd\u5339\u914d\u6587\u7ae0\u7c7b\u578b\n        'posts_per_page' =&gt; 1,                 \/\/ \u4ec5\u83b7\u53d61\u7bc7\u6587\u7ae0\n        'no_found_rows' =&gt; true,                \/\/ \u7981\u7528\u5206\u9875\u8ba1\u7b97\uff08\u8282\u7701\u8d44\u6e90\uff09\n        'update_post_meta_cache' =&gt; false,      \/\/ \u7981\u7528post meta\u7f13\u5b58\uff08\u51cf\u5c11\u67e5\u8be2\uff09\n        'update_post_term_cache' =&gt; false,      \/\/ \u7981\u7528\u5206\u7c7b\u672f\u8bed\u7f13\u5b58\uff08\u51cf\u5c11\u67e5\u8be2\uff09\n        'ignore_sticky_posts' =&gt; true,          \/\/ \u5ffd\u7565\u7f6e\u9876\u6587\u7ae0\uff08\u907f\u514d\u989d\u5916\u5904\u7406\uff09\n        'suppress_filters' =&gt; true,             \/\/ \u8df3\u8fc7\u975e\u5fc5\u8981\u8fc7\u6ee4\u5668\uff08\u63d0\u5347\u6027\u80fd\uff09\n    ];\n    \n    \/\/ \u521b\u5efa\u65b0\u7684\u67e5\u8be2\u5bf9\u8c61\n    $wp_query = new WP_Query($query_args);\n    \n    \/\/ \u9a8c\u8bc1\u67e5\u8be2\u7ed3\u679c\n    if (!$wp_query-&gt;have_posts()) {\n        \/\/ \u6062\u590d\u73af\u5883\u540e\u8fd4\u56de\n        $wp_query = $backup_query;\n        $post = $backup_post;\n        wp_suspend_cache_addition($original_cache_addition);\n        wp_suspend_cache_invalidation($original_cache_invalidation);\n        return false;\n    }\n    \n    \/\/ =====================================================================\n    \/\/ \u7b2c5\u90e8\u5206\uff1a\u8bbe\u7f6e\u5f53\u524d\u6587\u7ae0 - \u51c6\u5907\u6a21\u677f\u6e32\u67d3\n    \/\/ =====================================================================\n    \n    \/\/ \u8bbe\u7f6e\u5168\u5c40$post\u53d8\u91cf\n    $post = $wp_query-&gt;posts[0];\n    \n    \/\/ \u521d\u59cb\u5316\u6587\u7ae0\u6570\u636e\uff08\u8bbe\u7f6e\u5168\u5c40$postdata\uff09\n    setup_postdata($post);\n    \n    \/\/ =====================================================================\n    \/\/ \u7b2c6\u90e8\u5206\uff1a\u6a21\u677f\u6e32\u67d3 - \u7cbe\u786e\u5339\u914dWordPress\u5c42\u7ea7\n    \/\/ =====================================================================\n    \n    \/\/ \u5f00\u59cb\u8f93\u51fa\u7f13\u51b2\n    ob_start();\n    \n    \/\/ \u6839\u636e\u6587\u7ae0\u7c7b\u578b\u786e\u5b9a\u6a21\u677f\u5c42\u7ea7\n    $template_hierarchy = [];\n    $post_type = $post-&gt;post_type;\n    \n    if ('page' === $post_type) {\n        \/\/ \u9875\u9762\u6a21\u677f\u5c42\u7ea7\n        $page_template = get_page_template_slug($post);\n        if ($page_template) {\n            $template_hierarchy[] = $page_template;\n        }\n        $template_hierarchy[] = \"page-{$post-&gt;post_name}.php\";\n        $template_hierarchy[] = \"page-{$post-&gt;ID}.php\";\n        $template_hierarchy[] = 'page.php';\n        $template_hierarchy[] = 'singular.php';\n        $template_hierarchy[] = 'index.php';\n    } else {\n        \/\/ \u6587\u7ae0\/\u81ea\u5b9a\u4e49\u7c7b\u578b\u6a21\u677f\u5c42\u7ea7\n        $template_hierarchy[] = \"single-{$post_type}-{$post-&gt;post_name}.php\";\n        $template_hierarchy[] = \"single-{$post_type}.php\";\n        $template_hierarchy[] = 'single.php';\n        $template_hierarchy[] = 'singular.php';\n        $template_hierarchy[] = 'index.php';\n    }\n    \n    \/\/ \u8fc7\u6ee4\u7a7a\u503c\u5e76\u5b9a\u4f4d\u6a21\u677f\n    $filtered_templates = array_filter($template_hierarchy);\n    $located_template = locate_template($filtered_templates, false, false);\n    \n    \/\/ \u52a0\u8f7d\u6a21\u677f\n    if ($located_template) {\n        \/\/ \u4f7f\u7528WordPress\u6838\u5fc3\u52a0\u8f7d\u51fd\u6570\n        load_template($located_template, false);\n    } else {\n        \/\/ \u56de\u9000\u673a\u5236\uff1a\u4f7f\u7528WordPress\u6838\u5fc3\u9ed8\u8ba4\u6a21\u677f\n        if ('page' === $post_type) {\n            load_template(ABSPATH . WPINC . '\/theme-compat\/page.php', false);\n        } else {\n            load_template(ABSPATH . WPINC . '\/theme-compat\/single.php', false);\n        }\n    }\n    \n    \/\/ \u83b7\u53d6\u8f93\u51fa\u5185\u5bb9\n    $html = ob_get_clean();\n    \n    \/\/ =====================================================================\n    \/\/ \u7b2c7\u90e8\u5206\uff1a\u73af\u5883\u6062\u590d - \u786e\u4fdd\u7cfb\u7edf\u72b6\u6001\u5b8c\u6574\n    \/\/ =====================================================================\n    \n    \/\/ \u6062\u590d\u539f\u59cb\u67e5\u8be2\u5bf9\u8c61\n    $wp_query = $backup_query;\n    \n    \/\/ \u6062\u590d\u539f\u59cb\u6587\u7ae0\u5bf9\u8c61\n    $post = $backup_post;\n    \n    \/\/ \u91cd\u7f6e\u6587\u7ae0\u6570\u636e\uff08\u6e05\u7406setup_postdata\u8bbe\u7f6e\u7684\u5168\u5c40\u53d8\u91cf\uff09\n    wp_reset_postdata();\n    \n    \/\/ \u6062\u590d\u7f13\u5b58\u8bbe\u7f6e\n    wp_suspend_cache_addition($original_cache_addition);\n    wp_suspend_cache_invalidation($original_cache_invalidation);\n    \n    \/\/ =====================================================================\n    \/\/ \u7b2c8\u90e8\u5206\uff1a\u8fd4\u56de\u7ed3\u679c\n    \/\/ =====================================================================\n    \n    return $html;\n}\n\n\/\/ \u4f7f\u7528\u793a\u4f8b\uff1a\n\/\/ $html = zzw_high_performance_post_html(123);\n\/\/ if ($html) {\n\/\/     \/\/ \u5904\u7406HTML\u5185\u5bb9\n\/\/ } else {\n\/\/     \/\/ \u5904\u7406\u9519\u8bef\n\/\/ }<\/code><\/pre><h2 class=\"wp-block-heading\">\u4e24\u4e2a\u65b9\u6cd5\u7684\u5bf9\u6bd4\uff1a\u6838\u5fc3\u5dee\u5f02\u5bf9\u6bd4\u8868<\/h2><figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7279\u6027<\/th><th><code>zzw_get_post_html_locally<\/code><\/th><th><code>zzw_fast_get_post_html<\/code><\/th><\/tr><\/thead><tbody><tr><td><strong>\u5b9e\u73b0\u539f\u7406<\/strong><\/td><td>\u5b8c\u6574\u6a21\u62dfHTTP\u8bf7\u6c42\u751f\u547d\u5468\u671f<\/td><td>\u76f4\u63a5\u52a0\u8f7d\u5185\u5bb9+\u6a21\u677f<\/td><\/tr><tr><td><strong>\u8f93\u5165\u7c7b\u578b<\/strong><\/td><td>\u652f\u6301ID\u548cURL\u8def\u5f84<\/td><td>\u4ec5\u652f\u6301\u6587\u7ae0ID<\/td><\/tr><tr><td><strong>\u5904\u7406\u6d41\u7a0b<\/strong><\/td><td>\u5b8c\u6574\u8def\u7531\u89e3\u6790\u2192\u67e5\u8be2\u6784\u5efa\u2192\u6a21\u677f\u6e32\u67d3<\/td><td>\u76f4\u63a5\u67e5\u8be2\u2192\u6a21\u677f\u6e32\u67d3<\/td><\/tr><tr><td><strong>\u5168\u5c40\u5bf9\u8c61\u5904\u7406<\/strong><\/td><td>\u5907\u4efd\/\u91cd\u7f6e $wp, $wp_query, $post<\/td><td>\u4ec5\u5904\u7406 $wp_query \u548c $post<\/td><\/tr><tr><td><strong>\u6a21\u677f\u52a0\u8f7d\u65b9\u5f0f<\/strong><\/td><td>\u4f7f\u7528WordPress\u539f\u751f\u6a21\u677f\u5c42\u7ea7\u7cfb\u7edf<\/td><td>\u7b80\u5316\u7248\u6a21\u677f\u9009\u62e9\u903b\u8f91<\/td><\/tr><tr><td><strong>\u5f02\u5e38\u5904\u7406<\/strong><\/td><td>try-catch-finally\u5b8c\u6574\u9519\u8bef\u5904\u7406<\/td><td>\u65e0\u663e\u5f0f\u5f02\u5e38\u5904\u7406<\/td><\/tr><tr><td><strong>\u5185\u5b58\u5360\u7528<\/strong><\/td><td>\u9ad8 (\u7ea635-50MB)<\/td><td>\u4f4e (\u7ea615-25MB)<\/td><\/tr><tr><td><strong>\u6267\u884c\u65f6\u95f4<\/strong><\/td><td>\u8f83\u6162 (100-300ms)<\/td><td>\u6781\u5feb (50-150ms)<\/td><\/tr><tr><td><strong>\u9002\u7528\u573a\u666f<\/strong><\/td><td>\u9700\u8981\u7cbe\u786e\u6a21\u62df\u524d\u7aef\u8bbf\u95ee<\/td><td>\u540e\u53f0\u6279\u91cf\u5904\u7406<\/td><\/tr><\/tbody><\/table><\/figure>","protected":false},"excerpt":{"rendered":"<p>\u5728 WordPress \u670d\u52a1\u5668\u672c\u5730\u73af\u5883\u4e0b\uff0c\u786e\u5b9e\u6709\u66f4\u9ad8\u6548\u7684\u65b9\u6cd5\u76f4\u63a5\u83b7\u53d6\u6587\u7ae0\u6e90\u7801\u3002\u4ee5\u4e0b\u662f\u4f18\u5316\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u5b8c\u5168\u5728\u670d\u52a1\u5668\u5185\u90e8\u5904\u7406\uff1a \u91cd\u8981\u4e8b\u9879 \u6ce8\u610f\u672c\u6587\u63d0\u5230\u7684\u7684\u6240\u6709\u65b9\u6cd5\u4e2d\u6a21\u677f\u6e32\u67d3\u73af\u8282\u6781\u6709\u53ef\u80fd\u5b58\u5728\u9519\u8bef\u6216\u95ee\u9898\uff0c\u8bf7\u81ea\u884c\u9a8c\u8bc1\u5904\u7406\u3002\u4e3b\u8981\u4f4d\u7f6e\u5728\uff1a 1\u3001\u9875\u9762\u6e32\u67d3\u6216\u9875\u9762\u6574\u9875\u6e90\u7801\u83b7\u53d6\u4e0d\u5b8c\u6574\uff1b 2\u3001\u7ecf\u5178\u4e3b\u9898\u4e0e\u5757\u4e3b\u9898\u7f51\u7ad9\u7684\u517c\u5bb9\u95ee\u9898\u3002 \u544a\u77e5\uff1a\u5982\u679c\u672c\u7ad9\u4f5c..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[3204],"bjjc2nav":[34],"tuisongtax":[],"class_list":["post-4238","bjjc","type-bjjc","status-publish","hentry","tag-hqzyym","bjjc2nav-wptspz"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"\u83b7\u53d6\u6587\u7ae0\u9875\u6574\u9875\u6e90\u7801","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":"\u83b7\u53d6\u6587\u7ae0\u9875\u6574\u9875\u6e90\u7801"}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc\/4238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/types\/bjjc"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=4238"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=4238"},{"taxonomy":"bjjc2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc2nav?post=4238"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=4238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}