Wordpress 使用多个页面模板显示自定义帖子类型
我创建了一个自定义帖子类型,如:Wordpress 使用多个页面模板显示自定义帖子类型,wordpress,templates,custom-post-type,Wordpress,Templates,Custom Post Type,我创建了一个自定义帖子类型,如: register_post_type( 'foobar' , array( 'labels' => array( 'name' => __('Foobar'), 'singular_name' => __('Foobar') ), 'public' => true, 'has_archive' => tru
register_post_type( 'foobar' ,
array(
'labels' => array(
'name' => __('Foobar'),
'singular_name' => __('Foobar')
),
'public' => true,
'has_archive' => true,
'menu_icon' => 'dashicons-welcome-write-blog',
'supports' => ['title', 'editor', 'thumbnail']
)
);
之后,我创建了多个页面模板:
single-foo.php
single-bar.php 与
/*
*模板名称:随便什么
*模板帖子类型:帖子、页面、产品、foobar
*/
我通常会输出自定义帖子类型,如下所示:
<?php $args = array( 'post_type' => 'foobar', 'posts_per_page' => 1, 'orderby' => 'meta_value' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title("<h1>","</h1>");
echo '<p>';
the_content();
echo '</p>';
endwhile; ?>
我正在自定义帖子类型foobar中创建两篇新帖子,作为一篇帖子foo和另一篇帖子bar的模板
如何在同一页面上的一个CPT中输出多个页面模板?比如说,我在CPT中有7篇文章,它们都有不同的模板,必须在同一页面上输出 它真的能这样工作吗