{"id":59,"date":"2025-03-05T15:05:31","date_gmt":"2025-03-05T07:05:31","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/59.html"},"modified":"2025-12-11T09:56:17","modified_gmt":"2025-12-11T01:56:17","slug":"%e9%a6%96%e9%a1%b5%e4%b8%bb%e5%be%aa%e7%8e%af%e5%8c%85%e5%90%ab%e6%98%be%e7%a4%ba%e8%87%aa%e5%ae%9a%e4%b9%89%e6%96%87%e7%ab%a0%e7%b1%bb%e5%9e%8b%ef%bc%88custom-post-type%ef%bc%89%e6%96%87%e7%ab%a0","status":"publish","type":"bjjc","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/59.html","title":{"rendered":"WordPress\u9996\u9875\u6216\u5206\u7c7b\u9875\u5faa\u73af\u4e0d\u663e\u793a\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff08Custom Post Type\uff09\u4e2d\u7684\u6587\u7ae0\u7684\u89e3\u51b3\u529e\u6cd5"},"content":{"rendered":"<p>\u5728WordPress\u4e2d\uff0c\u5982\u679c\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff08Custom Post Type\uff09\u7684\u6587\u7ae0\u65e0\u6cd5\u5728\u9996\u9875\u663e\u793a\uff0c\u53ef\u80fd\u662f\u56e0\u4e3a\u9ed8\u8ba4\u7684\u4e3b\u5faa\u73af\uff08<code>have_posts()<\/code> \u548c <code>the_post()<\/code>\uff09\u53ea\u4f1a\u67e5\u8be2\u9ed8\u8ba4\u7684 <code>post<\/code> \u7c7b\u578b\u6587\u7ae0\uff0c\u800c\u4e0d\u4f1a\u81ea\u52a8\u5305\u542b\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0\u3002<\/p><p>\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u6765\u786e\u4fdd\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0\u5728\u9996\u9875\u663e\u793a\uff1a<\/p><h3 class=\"wp-block-heading\">\u65b9\u6cd51\uff1a\u4f7f\u7528 <code>pre_get_posts<\/code> \u94a9\u5b50\u4fee\u6539\u4e3b\u67e5\u8be2<\/h3><p>\u4f60\u53ef\u4ee5\u5728\u4e3b\u9898\u7684 <code>functions.php<\/code> \u6587\u4ef6\u4e2d\u4f7f\u7528 <code>pre_get_posts<\/code> \u94a9\u5b50\u6765\u4fee\u6539\u4e3b\u67e5\u8be2\uff0c\u4f7f\u5176\u5305\u542b\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0\u3002<\/p><pre class=\"wp-block-code\"><code>function zzw_include_custom_post_types_in_homepage( $query ) {\n    if ( $query-&gt;is_home() &amp;&amp; $query-&gt;is_main_query() ) {\n        $query-&gt;set( 'post_type', array( 'post', 'your_custom_post_type' ) ); \/\/ \u5c06 'your_custom_post_type' \u66ff\u6362\u4e3a\u4f60\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\n    }\n}\nadd_action( 'pre_get_posts', 'zzw_include_custom_post_types_in_homepage' );<\/code><\/pre><h3 class=\"wp-block-heading\">\u65b9\u6cd52\uff1a\u76f4\u63a5\u4fee\u6539\u9996\u9875\u6a21\u677f\u4e2d\u7684\u67e5\u8be2<\/h3><p>\u4f60\u4e5f\u53ef\u4ee5\u76f4\u63a5\u5728\u9996\u9875\u6a21\u677f\u4e2d\u4fee\u6539\u67e5\u8be2\uff0c\u4f7f\u7528 <code>WP_Query<\/code> \u6765\u83b7\u53d6\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0\u3002<\/p><pre class=\"wp-block-code\"><code>$args = array(\n    'post_type' =&gt; array( 'post', 'your_custom_post_type' ), \/\/ \u5c06 'your_custom_post_type' \u66ff\u6362\u4e3a\u4f60\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\n    'paged' =&gt; get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1\n);\n\n$custom_query = new WP_Query( $args );\n\nif ( $custom_query-&gt;have_posts() ) :\n    while ( $custom_query-&gt;have_posts() ) : $custom_query-&gt;the_post();\n        get_template_part( 'listli-noimg\/terms1-li' ); \/\/ \u6837\u5f0f\n    endwhile;\n\n    \/\/ \u5206\u9875\n    the_posts_pagination( array(\n        'prev_text' =&gt; __( '\u4e0a\u4e00\u9875', 'textdomain' ),\n        'next_text' =&gt; __( '\u4e0b\u4e00\u9875', 'textdomain' ),\n        'before_page_number' =&gt; '&lt;span class=\"meta-nav screen-reader-text\"&gt;' . __( 'Page', 'textdomain' ) . ' &lt;\/span&gt;',\n    ) );\n\n    wp_reset_postdata(); \/\/ \u91cd\u7f6e\u67e5\u8be2\nelse :\n    _e( '\u6682\u65f6\u6ca1\u6709\u5185\u5bb9\u3002', 'textdomain' );\nendif;<\/code><\/pre><h3 class=\"wp-block-heading\">\u65b9\u6cd53\uff1a\u4f7f\u7528\u63d2\u4ef6<\/h3><p>\u5982\u679c\u4f60\u4e0d\u60f3\u4fee\u6539\u4ee3\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u63d2\u4ef6\u6765\u5e2e\u52a9\u4f60\u5728\u9996\u9875\u663e\u793a\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0\u3002\u4f8b\u5982\uff0c\u63d2\u4ef6 &#8220;Custom Post Type UI&#8221; \u6216 &#8220;Query Multiple Taxonomies&#8221; \u53ef\u4ee5\u5e2e\u52a9\u4f60\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002<\/p><h3 class=\"wp-block-heading\">\u6ce8\u610f\u4e8b\u9879<\/h3><ol class=\"wp-block-list\">\n<li><strong>\u5206\u9875\u95ee\u9898<\/strong>\uff1a\u5982\u679c\u4f60\u4f7f\u7528\u4e86\u81ea\u5b9a\u4e49\u67e5\u8be2\uff08\u5982\u65b9\u6cd52\uff09\uff0c\u786e\u4fdd\u5206\u9875\u53c2\u6570\u6b63\u786e\u4f20\u9012\uff0c\u5426\u5219\u5206\u9875\u53ef\u80fd\u65e0\u6cd5\u6b63\u5e38\u5de5\u4f5c\u3002<\/li>\n\n\n\n<li><strong>\u6027\u80fd\u8003\u8651<\/strong>\uff1a\u5982\u679c\u4f60\u5728\u9996\u9875\u52a0\u8f7d\u4e86\u5927\u91cf\u7684\u6587\u7ae0\uff08\u5305\u62ec\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff09\uff0c\u53ef\u80fd\u4f1a\u5f71\u54cd\u9875\u9762\u52a0\u8f7d\u901f\u5ea6\u3002\u786e\u4fdd\u4f18\u5316\u67e5\u8be2\u6216\u4f7f\u7528\u5206\u9875\u6765\u51cf\u5c11\u4e00\u6b21\u6027\u52a0\u8f7d\u7684\u6587\u7ae0\u6570\u91cf\u3002<\/li>\n<\/ol><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u4f60\u5e94\u8be5\u80fd\u591f\u6210\u529f\u5728\u9996\u9875\u663e\u793a\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u5728WordPress\u4e2d\uff0c\u5982\u679c\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff08Custom Post Type\uff09\u7684\u6587\u7ae0\u65e0\u6cd5\u5728\u9996\u9875\u663e\u793a\uff0c\u53ef\u80fd\u662f\u56e0\u4e3a\u9ed8\u8ba4\u7684\u4e3b\u5faa\u73af\uff08have_posts() \u548c the_post()\uff09\u53ea\u4f1a\u67e5\u8be2\u9ed8\u8ba4\u7684 post \u7c7b\u578b\u6587\u7ae0\uff0c\u800c\u4e0d\u4f1a\u81ea\u52a8\u5305\u542b\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0\u3002 \u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u6765\u786e\u4fdd\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0\u5728\u9996\u9875..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":true},"tags":[],"bjjc2nav":[14],"tuisongtax":[],"class_list":["post-59","bjjc","type-bjjc","status-publish","hentry","bjjc2nav-jdztkf"],"acf":{"qian_art_seotitle":"WordPress\u9996\u9875\u6216\u5206\u7c7b\u9875\u5faa\u73af\u4e0d\u663e\u793a\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff08Custom Post Type\uff09\u4e2d\u7684\u6587\u7ae0\u7684\u89e3\u51b3\u529e\u6cd5","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":"WordPress\u9996\u9875\u6216\u5206\u7c7b\u9875\u5faa\u73af\u4e0d\u663e\u793a\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff08Custom Post Type\uff09\u4e2d\u7684\u6587\u7ae0\u7684\u89e3\u51b3\u529e\u6cd5"},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"\u9996\u9875\u6216\u5206\u7c7b\uff1a\u663e\u793a\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":"\u9996\u9875\u6216\u5206\u7c7b\uff1a\u663e\u793a\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0"}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc\/59","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=59"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=59"},{"taxonomy":"bjjc2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc2nav?post=59"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}