{"id":2838,"date":"2025-06-11T07:46:48","date_gmt":"2025-06-10T23:46:48","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/wpdt\/2838.html"},"modified":"2025-06-11T07:46:48","modified_gmt":"2025-06-10T23:46:48","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8wordpress%e4%b8%ad%e6%98%be%e7%a4%ba%e5%8f%97%e5%af%86%e7%a0%81%e4%bf%9d%e6%8a%a4%e7%9a%84%e6%96%87%e7%ab%a0%e6%91%98%e5%bd%95","status":"publish","type":"post","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/post\/2838.html","title":{"rendered":"\u5982\u4f55\u5728WordPress\u4e2d\u663e\u793a\u53d7\u5bc6\u7801\u4fdd\u62a4\u7684\u6587\u7ae0\u6458\u5f55"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<p class=\"my-0\">Bug&#32534;&#35793;&#29422;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#35201;&#22312;WordPress&#20013;&#26174;&#31034;&#21463;&#23494;&#30721;&#20445;&#25252;&#30340;&#25991;&#31456;&#25688;&#24405;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992;<code>the_password()<\/code>&#20989;&#25968;&#26469;&#23454;&#29616;&#36825;&#20010;&#21151;&#33021;&#12290;&#36825;&#20010;&#20989;&#25968;&#20801;&#35768;&#20320;&#22312;&#25991;&#31456;&#25110;&#39029;&#38754;&#30340;&#29305;&#23450;&#20301;&#32622;&#25554;&#20837;&#21463;&#23494;&#30721;&#20445;&#25252;&#30340;&#20869;&#23481;&#12290;<\/p>\n<h3>&#35299;&#37322;<\/h3>\n<ol>\n<li>\n<p><strong><code>the_password( $text, $password )<\/code><\/strong>:<\/p>\n<ul>\n<li><code>$text<\/code>: &#20320;&#38656;&#35201;&#20445;&#25252;&#30340;&#25991;&#26412;&#12290;<\/li>\n<li><code>$password<\/code>: &#29992;&#20110;&#35299;&#23494;&#21644;&#23637;&#31034;&#25991;&#26412;&#30340;&#23494;&#30721;&#23383;&#31526;&#20018;&#12290;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>&#20351;&#29992;&#27493;&#39588;<\/strong>:<\/p>\n<ul>\n<li>&#39318;&#20808;&#65292;&#22312;&#25991;&#31456;&#25110;&#39029;&#38754;&#20013;&#25214;&#21040;&#20320;&#24076;&#26395;&#25554;&#20837;&#21463;&#23494;&#30721;&#20445;&#25252;&#20869;&#23481;&#30340;&#20301;&#32622;&#12290;<\/li>\n<li>&#20351;&#29992;<code>the_password()<\/code>&#20989;&#25968;&#23558;&#35201;&#20445;&#25252;&#30340;&#25991;&#23383;&#20256;&#36882;&#32473;&#23427;&#65292;&#24182;&#25552;&#20379;&#19968;&#20010;&#23494;&#30721;&#20316;&#20026;&#21442;&#25968;&#12290;<\/li>\n<li>&#23558;&#32467;&#26524;&#25554;&#20837;&#21040;&#27169;&#26495;&#25991;&#20214;&#20013;&#30340;&#30456;&#24212;&#20301;&#32622;&#12290;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>&#31034;&#20363;&#20195;&#30721;<\/strong>:<\/p>\n<pre><code class=\"language-php\">\/\/ &#20551;&#35774;&#20320;&#24819;&#22312;&#25991;&#31456;&#30340;&#31532;&#19968;&#27573;&#25554;&#20837;&#21463;&#23494;&#30721;&#20445;&#25252;&#30340;&#20869;&#23481;\necho the_password('&lt;strong&gt;This is a protected text.&lt;\/strong&gt;', 'my_secret_password');<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>&#25928;&#26524;<\/strong>:\n&#24403;&#29992;&#25143;&#35775;&#38382;&#35813;&#25991;&#31456;&#26102;&#65292;&#20182;&#20204;&#23558;&#30475;&#21040;&ldquo;This is a protected text.&rdquo;&#65292;&#24182;&#34987;&#25552;&#31034;&#36755;&#20837;&#23494;&#30721;&#25165;&#33021;&#32487;&#32493;&#38405;&#35835;&#21097;&#20313;&#37096;&#20998;&#12290;<\/p>\n<\/li>\n<\/ol>\n<h3>&#27880;&#24847;&#20107;&#39033;<\/h3>\n<ul>\n<li>&#30830;&#20445;&#22312;&#25991;&#31456;&#25110;&#39029;&#38754;&#20013;&#27491;&#30830;&#24341;&#29992;&#20102;&#23494;&#30721;&#20445;&#25252;&#30340;&#25991;&#26412;&#65292;&#20197;&#36991;&#20813;&#28151;&#28102;&#12290;<\/li>\n<li>&#23494;&#30721;&#24212;&#35813;&#26159;&#23433;&#20840;&#30340;&#65292;&#19981;&#33021;&#20844;&#24320;&#27844;&#38706;&#12290;<\/li>\n<\/ul>\n<p>&#36890;&#36807;&#36825;&#31181;&#26041;&#24335;&#65292;&#20320;&#21487;&#20197;&#26377;&#25928;&#22320;&#22312;WordPress&#20013;&#23637;&#31034;&#21463;&#23494;&#30721;&#20445;&#25252;&#30340;&#20869;&#23481;&#65292;&#20026;&#29992;&#25143;&#25552;&#20379;&#26356;&#20010;&#24615;&#21270;&#30340;&#38405;&#35835;&#20307;&#39564;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;&#21069;&#30340;Bug&#35821;&#27861;&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<p class=\"my-0\">&#40657;&#26495;&#21069;&#30340;Bug&#35821;&#27861;&#35762;&#24072;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#35201;&#22312;WordPress&#20013;&#26174;&#31034;&#21463;&#23494;&#30721;&#20445;&#25252;&#30340;&#25991;&#31456;&#25688;&#24405;&#65292;&#20320;&#38656;&#35201;&#36981;&#24490;&#20197;&#19979;&#27493;&#39588;&#65306;<\/p>\n<ol>\n<li>\n<p>&#21019;&#24314;&#19968;&#20010;&#26032;&#20027;&#39064;&#25110;&#32773;&#20462;&#25913;&#29616;&#26377;&#20027;&#39064;&#12290;<\/p>\n<\/li>\n<li>\n<p>&#22312;<code>functions.php<\/code>&#25991;&#20214;&#20013;&#28155;&#21152;&#20197;&#19979;&#20195;&#30721;&#26469;&#21551;&#29992;&#23494;&#30721;&#20445;&#25252;&#65306;<\/p>\n<pre><code class=\"language-php\">function enable_password_protected_posts() {\nadd_theme_support('post-thumbnails');\nadd_post_type_support('page', 'custom');\nadd_post_type_support('post', 'custom');\n}\nadd_action('after_setup_theme', 'enable_password_protected_posts');<\/code><\/pre>\n<\/li>\n<li>\n<p>&#22312;<code>functions.php<\/code>&#25991;&#20214;&#20013;&#21019;&#24314;&#19968;&#20010;&#26032;&#30340;&#20989;&#25968;&#26469;&#22788;&#29702;&#23494;&#30721;&#20445;&#25252;&#25991;&#31456;&#30340;&#25688;&#35201;&#65306;<\/p>\n<pre><code class=\"language-php\">\nfunction get_password_protected_excerpt($content) {\n$excerpt_length = 50; \/\/ &#35774;&#32622;&#25688;&#35201;&#38271;&#24230;&#65288;&#40664;&#35748;&#20026;50&#23383;&#31526;&#65289;\n$post_id = get_the_ID(); \/\/ &#33719;&#21462;&#24403;&#21069;&#25991;&#31456;ID\n\nif (has_post_thumbnail($post_id)) { \/\/ &#26816;&#26597;&#26159;&#21542;&#20855;&#26377;&#22270;&#29255;\n    $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'full')[0];\n    $image_alt = wp_get_attachment_caption(get_post_thumbnail_id($post_id));\n    $content = str_replace($thumbnail_url, '&lt;img src=\"' . esc_url($thumbnail_url) . '\" alt=\"' . esc_attr($image_alt) . '\" \/&gt;', $content);\n}\n\nreturn apply_filters('the_content', $content, $post_id); \/\/ &#36820;&#22238;&#22788;&#29702;&#21518;&#30340;&#20869;&#23481;\n}<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>add_filter(&#8216;the_excerpt&#8217;, &#8216;get_password_protected_excerpt&#8217;, 10, 2);<\/p>\n<pre><code>\n4. &#20462;&#25913;`wp_head.php`&#25991;&#20214;&#20013;&#30340;`&lt;head&gt;`&#26631;&#31614;&#20869;&#30340;`&lt;style&gt;`&#37096;&#20998;&#65292;&#20197;&#30830;&#20445;&#26631;&#39064;&#26631;&#39064;&#24102;&#26377;&#23494;&#30721;&#20445;&#25252;&#26631;&#24535;&#65306;\n```html\n&lt;style&gt;\n    #password-protected-post h1 a,\n    #password-protected-post h2 a,\n    #password-protected-post h3 a,\n    #password-protected-post h4 a,\n    #password-protected-post h5 a,\n    #password-protected-post h6 a {\n        text-decoration: none;\n    }\n&lt;\/style&gt;<\/code><\/pre>\n<ol start=\"5\">\n<li>&#26368;&#21518;&#65292;&#22312;&#20320;&#30340;&#32593;&#31449;&#19978;&#28608;&#27963;&#24182;&#24212;&#29992;&#36825;&#20123;&#26356;&#25913;&#12290;<\/li>\n<\/ol>\n<p>&#29616;&#22312;&#65292;&#24403;&#29992;&#25143;&#23581;&#35797;&#35775;&#38382;&#21463;&#23494;&#30721;&#20445;&#25252;&#30340;&#25991;&#31456;&#26102;&#65292;&#20182;&#20204;&#23558;&#30475;&#21040;&#19968;&#20010;&#23494;&#30721;&#20445;&#25252;&#26631;&#24535;&#65292;&#24182;&#19988;&#20250;&#30475;&#21040;&#19968;&#27573;&#25688;&#35201;&#65292;&#36825;&#21462;&#20915;&#20110;&#25991;&#31456;&#30340;&#20869;&#23481;&#21644;&#35774;&#32622;&#12290;<\/p>\n<p>&#27880;&#24847;&#65306;&#36825;&#20010;&#20363;&#23376;&#20551;&#35774;&#20320;&#24050;&#32463;&#35774;&#32622;&#20102;&#27491;&#30830;&#30340;&#30331;&#24405;&#39029;&#38754;&#65292;&#24182;&#19988;&#20351;&#29992;&#20102;&#36866;&#24403;&#30340;&#23494;&#30721;&#20445;&#25252;&#26041;&#27861;&#26469;&#38450;&#27490;&#26410;&#32463;&#25480;&#26435;&#30340;&#35775;&#38382;&#12290;&#22914;&#26524;&#20320;&#27809;&#26377;&#36825;&#26679;&#20570;&#65292;&#35831;&#21442;&#32771;WordPress&#30340;&#23448;&#26041;&#25991;&#26723;&#25110;&#23547;&#27714;&#24110;&#21161;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#35201;&#22312;WordPress&#20013;&#26174;&#31034;&#21463;&#23494;&#30721;&#20445;&#25252;&#30340;&#25991;&#31456;&#25688;&#24405;&#038;#6..<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[59],"tuisongtax":[],"class_list":["post-2838","post","type-post","status-publish","format-standard","hentry","category-wpdt","tag-pzjc"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/2838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/comments?post=2838"}],"version-history":[{"count":0,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/2838\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=2838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/categories?post=2838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=2838"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=2838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}