对于这种情况,我创建了一个自定义页面模板,比如tpl-archive-page.php
.例如,使用Advanced Custom Fields 以及Post Type Selector Field(*)用户可以选择要连接的帖子类型。
<?php
/**
* Template Name: CPT Archive Page
*/
get_header();
while (have_posts()) :
the_post();
get_template_part(\'content\', \'page\');
$archive_query_post_type = get_post_meta(get_queried_object_id(), \'cpt_archive_query_post_type\', true);
if( $archive_query_post_type && is_string($archive_query_post_type) ) {
$args = array(
\'post_type\' => $archive_query_post_type,
\'posts_per_page\'=> -1,
\'orderby\' => \'title\',
);
$archive_query = new WP_Query( $args );
if ( $archive_query->have_posts() ) {
while ( $archive_query->have_posts() ) {
$archive_query->the_post();
get_template_part(\'content\', get_post_type() );
}
}
wp_reset_postdata();
}
endwhile;
get_footer();
The
has_archive
注册自定义帖子类型时的选项必须设置为
false
.
(*)如果您使用的是ACF5/Pro,请考虑this 分岔路口。