{"id":2380,"date":"2025-06-11T01:34:12","date_gmt":"2025-06-10T17:34:12","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/wpdt\/2380.html"},"modified":"2025-06-11T01:34:12","modified_gmt":"2025-06-10T17:34:12","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-wordpress-%e6%90%9c%e7%b4%a2%e7%bb%93%e6%9e%9c%e4%b8%ad%e5%8c%85%e5%90%ab%e8%87%aa%e5%ae%9a%e4%b9%89%e6%96%87%e7%ab%a0%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/post\/2380.html","title":{"rendered":"\u5982\u4f55\u5728 WordPress \u641c\u7d22\u7ed3\u679c\u4e2d\u5305\u542b\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b"},"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&#20013;&#65292;&#22914;&#26524;&#20320;&#24819;&#35753;&#25628;&#32034;&#32467;&#26524;&#20013;&#30340;&#25991;&#31456;&#19981;&#20165;&#21253;&#25324;&#40664;&#35748;&#30340;&#24086;&#23376;&#65288;post&#65289;&#65292;&#36824;&#21253;&#25324;&#33258;&#23450;&#20041;&#30340;&#25991;&#31456;&#31867;&#22411;&#65288;&#22914;&#39029;&#38754;&#12289;&#20998;&#31867;&#39029;&#31561;&#65289;&#65292;&#20320;&#38656;&#35201;&#36890;&#36807;&#20462;&#25913;&#25628;&#32034;&#26597;&#35810;&#26469;&#23454;&#29616;&#36825;&#19968;&#28857;&#12290;<\/p>\n<h3>&#26041;&#27861;&#19968;&#65306;&#25163;&#21160;&#28155;&#21152;&#25628;&#32034;&#21442;&#25968;<\/h3>\n<ol>\n<li>\n<p><strong>&#25171;&#24320; <code>functions.php<\/code> &#25991;&#20214;<\/strong>&#65306;\n&#36890;&#24120;&#20301;&#20110; <code>\/wp-content\/themes\/your-theme-name\/<\/code> &#30446;&#24405;&#19979;&#12290;<\/p>\n<\/li>\n<li>\n<p><strong>&#32534;&#20889;&#20195;&#30721;<\/strong>&#65306;\n&#22312;&#25991;&#20214;&#20013;&#25214;&#21040;&#25110;&#28155;&#21152;&#20197;&#19979;&#20195;&#30721;&#65306;<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"language-php\">function search_custom_post_types($query) {\n    if ($query-&gt;is_search &amp;&amp; $query-&gt;is_main_query()) {\n        $args = array(\n            'post_type' =&gt; array('page', 'custom_post_type_name'), \/\/ &#26367;&#25442;&#20026;&#20320;&#30340;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#30340;&#21517;&#31216;\n            'posts_per_page' =&gt; -1, \/\/ &#26174;&#31034;&#25152;&#26377;&#30456;&#20851;&#25991;&#31456;\n        );\n        $query-&gt;set('s', $query-&gt;get('s')); \/\/ &#32487;&#32493;&#20351;&#29992;&#21407;&#25628;&#32034;&#35789;\n        $query-&gt;set('post__not_in', array(0)); \/\/ &#30830;&#20445;&#19981;&#26174;&#31034;&#24050;&#21024;&#38500;&#25991;&#31456;\n        $query-&gt;set('orderby', 'title'); \/\/ &#25490;&#24207;&#26041;&#24335;\n        $query-&gt;set('order', 'ASC');\n        $query-&gt;set('meta_key', '_menu_order'); \/\/ &#22914;&#26524;&#26377;&#29305;&#23450;&#25490;&#24207;&#20381;&#25454;\n        $query-&gt;set('meta_value', $query-&gt;get('paged'));\n        $query-&gt;set('paged', $query-&gt;get('paged', 0, true));\n    }\n}\nadd_action('pre_get_posts', 'search_custom_post_types');<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p><strong>&#26367;&#25442;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#21517;&#31216;<\/strong>&#65306;\n&#23558; <code>'custom_post_type_name'<\/code> &#26367;&#25442;&#20026;&#20320;&#23454;&#38469;&#30340;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#21517;&#31216;&#12290;<\/p>\n<\/li>\n<li>\n<p><strong>&#20445;&#23384;&#24182;&#28608;&#27963;&#26356;&#26032;<\/strong>&#65306;\n&#20462;&#25913;&#23436;&#25104;&#21518;&#65292;&#35760;&#24471;&#20445;&#23384;&#24182;&#28608;&#27963;&#24744;&#30340;&#20027;&#39064;&#20197;&#24212;&#29992;&#26356;&#25913;&#12290;<\/p>\n<\/li>\n<\/ol>\n<h3>&#31034;&#20363;&#25928;&#26524;<\/h3>\n<p>&#20551;&#35774;&#24744;&#26377;&#19968;&#20010;&#21517;&#20026;&ldquo;news&rdquo;&#30340;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#21644;&#19968;&#20010;&#21517;&#20026;&ldquo;archive&rdquo;&#30340;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#39029;&#38754;&#12290;&#24403;&#29992;&#25143;&#22312;&#25628;&#32034;&#26694;&#20013;&#36755;&#20837;&#20851;&#38190;&#35789;&#26102;&#65292;&#25628;&#32034;&#32467;&#26524;&#20250;&#21516;&#26102;&#26174;&#31034;&#36825;&#20004;&#31867;&#25991;&#31456;&#65292;&#32780;&#19981;&#20250;&#24433;&#21709;&#20854;&#20182;&#40664;&#35748;&#25991;&#31456;&#31867;&#22411;&#30340;&#32467;&#26524;&#12290;<\/p>\n<h3>&#27880;&#24847;&#20107;&#39033;<\/h3>\n<ul>\n<li>&#36825;&#20010;&#26041;&#27861;&#21482;&#36866;&#29992;&#20110;&#22522;&#26412;&#30340;&#25628;&#32034;&#21151;&#33021;&#65292;&#23545;&#20110;&#26356;&#22797;&#26434;&#30340;&#25628;&#32034;&#38656;&#27714;&#65292;&#21487;&#33021;&#38656;&#35201;&#20351;&#29992;&#25554;&#20214;&#25110;&#31532;&#19977;&#26041;&#26381;&#21153;&#12290;<\/li>\n<li>&#23545;&#20110;&#21160;&#24577;&#25628;&#32034;&#65288;&#22914;&#20351;&#29992; <code>WP_Query<\/code> &#25110;&#32773;&#33258;&#23450;&#20041;&#25628;&#32034;&#25554;&#20214;&#65289;&#30340;&#39640;&#32423;&#25628;&#32034;&#21151;&#33021;&#65292;&#36825;&#31181;&#26041;&#27861;&#21487;&#33021;&#26080;&#27861;&#23436;&#20840;&#28385;&#36275;&#38656;&#27714;&#12290;<\/li>\n<\/ul>\n<p>&#24076;&#26395;&#36825;&#20010;&#26041;&#27861;&#33021;&#24110;&#21161;&#20320;&#22312;WordPress&#20013;&#23454;&#29616;&#25628;&#32034;&#32467;&#26524;&#21253;&#21547;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#30340;&#38656;&#27714;&#65281;&#22914;&#26524;&#20320;&#26377;&#20219;&#20309;&#30097;&#38382;&#65292;&#35831;&#38543;&#26102;&#25552;&#38382;&#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 &#30340;&#25628;&#32034;&#32467;&#26524;&#20013;&#21253;&#21547;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#65292;&#20320;&#38656;&#35201;&#36981;&#24490;&#20197;&#19979;&#27493;&#39588;&#65306;<\/p>\n<h3>1. &#23433;&#35013;&#24182;&#37197;&#32622;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;<\/h3>\n<p>&#39318;&#20808;&#65292;&#30830;&#20445;&#20320;&#30340;&#32593;&#31449;&#24050;&#32463;&#23433;&#35013;&#20102;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#25554;&#20214;&#12290;&#22914;&#26524;&#20320;&#36824;&#27809;&#26377;&#65292;&#20320;&#21487;&#20197;&#20174; WordPress &#25554;&#20214;&#21830;&#24215;&#19979;&#36733;&#24182;&#23433;&#35013;&#19968;&#20010;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#25554;&#20214;&#12290;<\/p>\n<h4>&#31034;&#20363;&#20195;&#30721;&#65306;<\/h4>\n<pre><code class=\"language-html\">&lt;div class=\"custom-post-type\"&gt;\n    &lt;h2&gt;&lt;?php _e( 'Custom Post Type', 'your-plugin' ); ?&gt;&lt;\/h2&gt;\n    &lt;?php the_posts_pagination(); ?&gt;\n    &lt;div class=\"post-list\"&gt;\n        &lt;?php wp_list_categories(array('orderby' =&gt; 'name', 'order' =&gt; 'ASC')); ?&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;<\/code><\/pre>\n<p>&#36825;&#20010;&#31034;&#20363;&#20195;&#30721;&#21019;&#24314;&#20102;&#19968;&#20010;&#21253;&#21547;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#30340;&#21015;&#34920;&#39029;&#38754;&#65292;&#23427;&#20250;&#21015;&#20986;&#24403;&#21069;&#20027;&#39064;&#30340;&#25152;&#26377;&#20998;&#31867;&#12290;<\/p>\n<h3>2. &#22312; WordPress &#20013;&#35774;&#32622;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;<\/h3>\n<p>&#25509;&#19979;&#26469;&#65292;&#22312; WordPress &#30340;&#20027;&#39064;&#25991;&#20214;&#20013;&#35774;&#32622;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#12290;&#36825;&#36890;&#24120;&#28041;&#21450;&#21040;&#20462;&#25913; <code>functions.php<\/code> &#25991;&#20214;&#25110; <code>wp-config.php<\/code> &#25991;&#20214;&#20013;&#30340;&#30456;&#20851;&#37096;&#20998;&#12290;<\/p>\n<h4>&#31034;&#20363;&#20195;&#30721;&#65306;<\/h4>\n<p>&#20551;&#35774;&#25105;&#20204;&#26377;&#19968;&#20010;&#21517;&#20026; <code>my_custom_post_type<\/code> &#30340;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#65292;&#24182;&#19988;&#20320;&#24819;&#23558;&#20854;&#21629;&#21517;&#20026; &#8220;My Custom Post&#8221;.<\/p>\n<p>&#22312; <code>functions.php<\/code> &#25110;&#32773; <code>wp-config.php<\/code> &#20013;&#28155;&#21152;&#22914;&#19979;&#20195;&#30721;&#65306;<\/p>\n<pre><code class=\"language-php\">function my_custom_post_type_setup() {\n    register_post_type(\n        'my_custom_post_type',\n        array(\n            'labels' =&gt; array(\n                'name' =&gt; __( 'My Custom Post Type' ),\n                'singular_name' =&gt; __( 'My Custom Post' ),\n                'add_new' =&gt; __( 'Add New' ),\n                'add_new_item' =&gt; __( 'Add New My Custom Post' ),\n                'edit_item' =&gt; __( 'Edit My Custom Post' ),\n                'new_item' =&gt; __( 'New My Custom Post' ),\n                'view_item' =&gt; __( 'View My Custom Post' ),\n                'search_items' =&gt; __( 'Search My Custom Posts' ),\n                'not_found' =&gt; __( 'No My Custom Posts found' ),\n                'not_found_in_trash' =&gt; __( 'No My Custom Posts found in Trash' )\n            ),\n            'public' =&gt; true,\n            'show_ui' =&gt; true,\n            'query_var' =&gt; true,\n            'rewrite' =&gt; array( 'slug' =&gt; 'my-custom-post-type' ),\n            'capability_type' =&gt; 'post',\n            'has_archive' =&gt; true,\n            'menu_icon' =&gt; 'dashicons-format-image',\n            'description' =&gt; __( 'This is a custom post type.' )\n        )\n    );\n}\nadd_action( 'after_setup_theme', 'my_custom_post_type_setup' );<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;&#25105;&#20204;&#23558;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#21629;&#21517;&#20026; &#8220;My Custom Post&#8221; &#24182;&#35774;&#32622;&#20102;&#20854;&#25551;&#36848;&#21644;&#31867;&#21035;&#12290;<\/p>\n<h3>3. &#26356;&#26032; WordPress &#20027;&#39064;&#26679;&#24335;<\/h3>\n<p>&#20026;&#20102;&#20351;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#30475;&#36215;&#26469;&#26356;&#20687;&#21407;&#29983;&#25991;&#31456;&#65292;&#38656;&#35201;&#26356;&#26032;&#30456;&#24212;&#20027;&#39064;&#30340;&#26679;&#24335;&#12290;&#36825;&#21487;&#33021;&#28041;&#21450;&#20462;&#25913; <code>.css<\/code> &#25991;&#20214;&#12289;&#20351;&#29992; CSS &#31867;&#31561;&#12290;<\/p>\n<h4>&#31034;&#20363;&#20195;&#30721;&#65306;<\/h4>\n<p>&#22312;&#24744;&#30340;&#20027;&#39064;&#30446;&#24405;&#19979;&#30340; <code>.css<\/code> &#25991;&#20214;&#20013;&#65292;&#26597;&#25214;&#26377;&#20851;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#30340;&#31867;&#21517;&#65292;&#28982;&#21518;&#21024;&#38500;&#19981;&#30456;&#20851;&#30340;&#31867;&#12290;&#20363;&#22914;&#65306;<\/p>\n<pre><code class=\"language-css\">.my-custom-post-type { \/* &#21024;&#38500;&#19982;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#26080;&#20851;&#30340;&#31867; *\/}<\/code><\/pre>\n<h3>4. &#27979;&#35797;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;<\/h3>\n<p>&#26368;&#21518;&#19968;&#27493;&#26159;&#27979;&#35797;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#26159;&#21542;&#25353;&#39044;&#26399;&#24037;&#20316;&#12290;&#21487;&#20197;&#20351;&#29992;&#20197;&#19979;&#20195;&#30721;&#26469;&#39564;&#35777;&#65306;<\/p>\n<pre><code class=\"language-php\">function test_my_custom_post_type() {\n    global $wpdb;\n    $args = array(\n        'post_type' =&gt; 'my_custom_post_type',\n        'posts_per_page' =&gt; -1,\n    );\n    $result = $wpdb-&gt;get_results(\"SELECT * FROM {$wpdb-&gt;posts} WHERE post_type='my_custom_post_type'\");\n    if (count($result) &gt; 0) {\n        echo \"Test passed: The custom post type is working as expected.\";\n    } else {\n        echo \"Test failed: There are no posts of this custom post type.\";\n    }\n}\n\ntest_my_custom_post_type();<\/code><\/pre>\n<h3>&#24635;&#32467;<\/h3>\n<p>&#36890;&#36807;&#20197;&#19978;&#27493;&#39588;&#65292;&#20320;&#21487;&#20197;&#22312; WordPress &#30340;&#25628;&#32034;&#32467;&#26524;&#20013;&#21253;&#21547;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#12290;&#35760;&#20303;&#65292;&#27599;&#20010;&#33258;&#23450;&#20041;&#25991;&#31456;&#31867;&#22411;&#30340;&#23454;&#29616;&#37117;&#26159;&#29420;&#19968;&#26080;&#20108;&#30340;&#65292;&#20855;&#20307;&#21462;&#20915;&#20110;&#20320;&#30340;&#38656;&#27714;&#21644;&#32593;&#31449;&#35774;&#35745;&#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&#20013;&#65292;&#22914;&#26524;&#20320;&#24819;&#35753;&#25628;&#32034;&#32467;&#26524;&#20013;&#30340;&#25991;&#038;#3..<\/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-2380","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\/2380","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=2380"}],"version-history":[{"count":0,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/2380\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=2380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/categories?post=2380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=2380"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=2380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}