{"id":1960,"date":"2025-06-10T18:21:05","date_gmt":"2025-06-10T10:21:05","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/wpdt\/1960.html"},"modified":"2025-06-14T11:42:18","modified_gmt":"2025-06-14T03:42:18","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8%e4%bd%a0%e7%9a%84wordpress%e4%b8%bb%e9%a2%98%e4%b8%ad%e6%98%be%e7%a4%ba%e6%9c%89%e9%99%90%e6%95%b0%e9%87%8f%e7%9a%84%e6%a0%87%e7%ad%be%e5%9c%a8%e5%b8%96%e5%ad%90%e5%90%8e","status":"publish","type":"post","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/post\/1960.html","title":{"rendered":"\u5982\u4f55\u5728\u4f60\u7684WordPress\u4e3b\u9898\u4e2d\u663e\u793a\u6709\u9650\u6570\u91cf\u7684\u6807\u7b7e\u5728\u5e16\u5b50\u540e"},"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>&#22312;WordPress&#20027;&#39064;&#20013;&#26174;&#31034;&#26377;&#38480;&#25968;&#37327;&#30340;&#26631;&#31614;&#22312;&#24086;&#23376;&#21518;&#38754;&#65292;&#21487;&#20197;&#20351;&#29992;<code>get_the_tags()<\/code>&#20989;&#25968;&#26469;&#33719;&#21462;&#24403;&#21069;&#24086;&#23376;&#30340;&#25152;&#26377;&#26631;&#31614;&#65292;&#28982;&#21518;&#20351;&#29992;<code>get_posts()<\/code>&#20989;&#25968;&#26469;&#33719;&#21462;&#29305;&#23450;&#25968;&#37327;&#30340;&#26631;&#31614;&#65292;&#26368;&#21518;&#36890;&#36807;&#24490;&#29615;&#36941;&#21382;&#36825;&#20123;&#26631;&#31614;&#24182;&#23558;&#20854;&#28155;&#21152;&#21040;&#24086;&#23376;&#30340;&#20869;&#23481;&#37096;&#20998;&#12290;<\/p>\n<p>&#20197;&#19979;&#26159;&#19968;&#20010;&#31034;&#20363;&#20195;&#30721;&#65306;<\/p>\n<pre><code class=\"language-php\">\/\/ &#33719;&#21462;&#24403;&#21069;&#24086;&#23376;&#30340;&#25152;&#26377;&#26631;&#31614;\n$tags = get_the_tags();\n\n\/\/ &#30830;&#23450;&#35201;&#26174;&#31034;&#30340;&#26368;&#22823;&#26631;&#31614;&#25968;&#65288;&#20363;&#22914;&#65292;5&#20010;&#65289;\n$max_num = 5;\n\n\/\/ &#36941;&#21382;&#25152;&#26377;&#26631;&#31614;\nforeach ($tags as $tag) {\n    \/\/ &#26816;&#26597;&#26159;&#21542;&#24050;&#32463;&#36229;&#36807;&#20102;&#26368;&#22823;&#26631;&#31614;&#25968;\n    if (count($tags) &gt; $max_num) break;\n\n    \/\/ &#23558;&#26631;&#31614;&#28155;&#21152;&#21040;&#24086;&#23376;&#20869;&#23481;&#37096;&#20998;\n    echo '&lt;a href=\"' . esc_url(get_tag_link($tag-&gt;term_id)) . '\" title=\"' . esc_attr(sprintf(__('View all posts tagged %s', 'textdomain'), $tag-&gt;name)) . '\"&gt;' . esc_html($tag-&gt;name) . '&lt;\/a&gt;';\n}<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#31034;&#20363;&#20013;&#65292;&#25105;&#20204;&#39318;&#20808;&#20351;&#29992;<code>get_the_tags()<\/code>&#20989;&#25968;&#33719;&#21462;&#20102;&#24403;&#21069;&#24086;&#23376;&#30340;&#25152;&#26377;&#26631;&#31614;&#12290;&#28982;&#21518;&#65292;&#25105;&#20204;&#30830;&#23450;&#20102;&#25105;&#20204;&#35201;&#26174;&#31034;&#30340;&#26368;&#22823;&#26631;&#31614;&#25968;&#65288;&#36825;&#37324;&#35774;&#20026;5&#65289;&#12290;&#25509;&#19979;&#26469;&#65292;&#25105;&#20204;&#20351;&#29992;<code>foreach<\/code>&#24490;&#29615;&#36941;&#21382;&#36825;&#20123;&#26631;&#31614;&#65292;&#26816;&#26597;&#26159;&#21542;&#24050;&#32463;&#36229;&#36807;&#20102;&#26368;&#22823;&#26631;&#31614;&#25968;&#12290;&#22914;&#26524;&#36229;&#36807;&#20102;&#65292;&#21017;&#36339;&#20986;&#24490;&#29615;&#12290;&#21542;&#21017;&#65292;&#25105;&#20204;&#23558;&#27599;&#20010;&#26631;&#31614;&#28155;&#21152;&#21040;&#24086;&#23376;&#30340;&#20869;&#23481;&#37096;&#20998;&#12290;&#26368;&#21518;&#65292;&#25105;&#20204;&#20351;&#29992;<code>esc_url()<\/code>&#21644;<code>esc_html()<\/code>&#20989;&#25968;&#23545;&#38142;&#25509;&#21644;&#25991;&#26412;&#36827;&#34892;&#20102;&#23433;&#20840;&#22788;&#29702;&#12290;<\/p>\n<p>&#27880;&#24847;&#65306;&#36825;&#20010;&#31034;&#20363;&#20551;&#35774;&#20320;&#22312;&#20027;&#39064;&#30340;<code>functions.php<\/code>&#25991;&#20214;&#25110;&#19968;&#20010;&#33258;&#23450;&#20041;&#30340;PHP&#25991;&#20214;&#20013;&#32534;&#20889;&#36825;&#27573;&#20195;&#30721;&#12290;&#22914;&#26524;&#20320;&#26159;&#22312;&#20351;&#29992;&#25554;&#20214;&#65292;&#35831;&#30830;&#20445;&#35813;&#25554;&#20214;&#20801;&#35768;&#20462;&#25913;&#20027;&#39064;&#30340;&#28304;&#20195;&#30721;&#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;&#23454;&#29616;&#36825;&#19968;&#28857;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992;WordPress&#30340;&#20027;&#39064;&#21151;&#33021;&#26469;&#38480;&#21046;&#26631;&#31614;&#30340;&#25968;&#37327;&#24182;&#23558;&#20854;&#24212;&#29992;&#20110;&#24086;&#23376;&#12290;&#20197;&#19979;&#26159;&#19968;&#20123;&#27493;&#39588;&#21644;&#31034;&#20363;&#20195;&#30721;&#65306;<\/p>\n<h3>&#27493;&#39588; 1: &#28155;&#21152;&#25110;&#20462;&#25913;&#20027;&#39064;&#27169;&#26495;&#25991;&#20214;<\/h3>\n<p>&#39318;&#20808;&#65292;&#22312;&#20320;&#30340;&#20027;&#39064;&#30340;<code>inc\/loop.php<\/code>&#25991;&#20214;&#20013;&#25214;&#21040;&#30456;&#20851;&#37096;&#20998;&#65292;&#20363;&#22914;&#65306;<\/p>\n<pre><code class=\"language-php\">&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;\n    &lt;?php get_template_part( 'content', 'single' ); ?&gt;\n&lt;?php endwhile; endif; ?&gt;<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;&#25105;&#20204;&#26816;&#26597;&#26159;&#21542;&#26377;&#26032;&#30340;&#24086;&#23376;&#65288;<code>have_posts()<\/code>&#65289;&#65292;&#22914;&#26524;&#26377;&#65292;&#21017;&#32487;&#32493;&#22788;&#29702;&#24086;&#23376;&#30340;&#20869;&#23481;&#12290;<\/p>\n<h3>&#27493;&#39588; 2: &#28155;&#21152;&#33258;&#23450;&#20041;&#36755;&#20986;<\/h3>\n<p>&#25509;&#19979;&#26469;&#65292;&#20320;&#38656;&#35201;&#28155;&#21152;&#19968;&#20010;&#33258;&#23450;&#20041;&#30340;&#36755;&#20986;&#65292;&#29992;&#20110;&#26174;&#31034;&#29305;&#23450;&#25968;&#37327;&#30340;&#26631;&#31614;&#12290;&#36825;&#21487;&#20197;&#36890;&#36807;&#23558;<code>&lt;div&gt;<\/code>&#20803;&#32032;&#23884;&#22871;&#22312;<code>&lt;ul&gt;<\/code>&#20803;&#32032;&#20869;&#26469;&#23436;&#25104;&#65292;&#22914;&#19979;&#25152;&#31034;&#65306;<\/p>\n<pre><code class=\"language-html\">&lt;div class=\"post-tags\"&gt;\n    &lt;ul&gt;\n        &lt;?php foreach ( $tags as $tag ) : ?&gt;\n            &lt;li&gt;&lt;a href=\"&lt;?php echo esc_url( get_tag_link( $tag-&gt;term_id ) ); ?&gt;\"&gt;&lt;?php echo $tag-&gt;name; ?&gt;&lt;\/a&gt;&lt;\/li&gt;\n        &lt;?php endforeach; ?&gt;\n    &lt;\/ul&gt;\n&lt;\/div&gt;<\/code><\/pre>\n<p>&#36825;&#37324;&#65292;&#25105;&#20204;&#23558;&#27599;&#20010;&#26631;&#31614;&#38142;&#25509;&#21040;&#20854;&#23545;&#24212;&#30340;&#26631;&#31614;&#39029;&#38754;&#65292;&#24182;&#36890;&#36807;<code>get_tag_link()<\/code>&#20989;&#25968;&#33719;&#21462;&#26631;&#31614;&#38142;&#25509;&#12290;<\/p>\n<h3>&#27493;&#39588; 3: &#20462;&#25913;&#36755;&#20986;&#26679;&#24335;<\/h3>\n<p>&#20026;&#20102;&#20351;&#36755;&#20986;&#26356;&#32654;&#35266;&#65292;&#20320;&#21487;&#20197;&#35843;&#25972;CSS&#26679;&#24335;&#20197;&#36866;&#24212;&#20320;&#30340;&#38656;&#27714;&#12290;&#20363;&#22914;&#65292;&#21487;&#20197;&#20351;&#29992;CSS&#36873;&#25321;&#22120;&#26469;&#25913;&#21464;&#23383;&#20307;&#22823;&#23567;&#12289;&#39068;&#33394;&#31561;&#12290;<\/p>\n<pre><code class=\"language-css\">.post-tags {\n    list-style-type: none;\n}\n\n.post-tags li {\n    display: inline-block;\n    margin-right: 5px;\n}\n\n.post-tags a {\n    color: #000;\n}<\/code><\/pre>\n<h3>&#27493;&#39588; 4: &#22312;&#20027;&#39064;&#24067;&#23616;&#20013;&#24212;&#29992;<\/h3>\n<p>&#26368;&#21518;&#65292;&#30830;&#20445;&#26356;&#26032;&#20320;&#30340;&#20027;&#39064;&#30340;<code>header.php<\/code>&#25110;<code>footer.php<\/code>&#25991;&#20214;&#20013;&#30340;<code>wp_nav_menu()<\/code>&#35843;&#29992;&#65292;&#20197;&#20415;&#22312;&#20027;&#39029;&#25110;&#20854;&#20182;&#39029;&#19978;&#27491;&#30830;&#24212;&#29992;&#33258;&#23450;&#20041;&#36755;&#20986;&#12290;<\/p>\n<h3>&#31034;&#20363;&#20195;&#30721;<\/h3>\n<p>&#19979;&#38754;&#26159;&#19968;&#20010;&#31616;&#21333;&#30340;&#31034;&#20363;&#65292;&#23637;&#31034;&#20102;&#22914;&#20309;&#22312;&#21333;&#20010;&#24086;&#23376;&#21518;&#38754;&#26174;&#31034;&#26368;&#22810;&#19977;&#20010;&#26631;&#31614;&#65306;<\/p>\n<pre><code class=\"language-php\">&lt;?php\nif ( have_posts() ) :\n    while ( have_posts() ) : the_post();\n\n        $tags = get_the_tags();\n        if ( ! empty( $tags ) &amp;&amp; count( $tags ) &gt; 0 ) :\n\n            echo '&lt;div class=\"post-tags\"&gt;';\n                foreach ( $tags as $tag ) :\n                    echo '&lt;a href=\"' . get_tag_link( $tag-&gt;term_id ) . '\"&gt;' . $tag-&gt;name . '&lt;\/a&gt;';\n                endforeach;\n\n                if ( count( $tags ) &gt;= 3 ) {\n                    echo '&lt;span class=\"more-tags\"&gt;...and more...&lt;\/span&gt;';\n                } else {\n                    echo '&lt;span class=\"all-tagged\"&gt;' . implode(', ', array_slice( $tags, 0, 3 )) . '&lt;\/span&gt;';\n                }\n            echo '&lt;\/div&gt;';\n\n        endif;\n    endwhile;\nendif;\n?&gt;<\/code><\/pre>\n<p>&#36825;&#20010;&#31034;&#20363;&#20250;&#22312;&#27599;&#20010;&#24086;&#23376;&#21518;&#38754;&#26174;&#31034;&#26368;&#22810;&#19977;&#20010;&#26631;&#31614;&#65292;&#24182;&#22312;&#26377;&#26356;&#22810;&#26631;&#31614;&#26102;&#28155;&#21152;&ldquo;&#8230; and more&hellip;&rdquo;&#12290;<\/p>\n<h3>&#24635;&#32467;<\/h3>\n<p>&#36890;&#36807;&#20197;&#19978;&#27493;&#39588;&#65292;&#20320;&#21487;&#20197;&#36731;&#26494;&#22320;&#22312;WordPress&#20027;&#39064;&#20013;&#21160;&#24577;&#23637;&#31034;&#26377;&#38480;&#25968;&#37327;&#30340;&#26631;&#31614;&#12290;&#21482;&#38656;&#26681;&#25454;&#23454;&#38469;&#38656;&#35201;&#35843;&#25972;HTML&#21644;CSS&#20195;&#30721;&#21363;&#21487;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#22312;WordPress&#20027;&#39064;&#20013;&#26174;&#31034;&#26377;&#38480;&#25968;&#37327;&#30340;&#26631;&#31614;&#22312;&#24086;&#038;#2..<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[3189,52,53],"tuisongtax":[],"class_list":["post-1960","post","type-post","status-publish","format-standard","hentry","category-wpdt","tag-zt","tag-ztjc","tag-ztmbpzjc"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/1960","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=1960"}],"version-history":[{"count":0,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/1960\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=1960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/categories?post=1960"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=1960"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=1960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}