Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 使用多个页面模板显示自定义帖子类型_Wordpress_Templates_Custom Post Type - Fatal编程技术网

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篇文章,它们都有不同的模板,必须在同一页面上输出

它真的能这样工作吗