我有一个儿童主题,有两个自定义帖子类型“爵士俱乐部”和“爵士音乐节”。我想要single.php
根据帖子是来自爵士俱乐部还是爵士音乐节,显示不同的内容。
问题是,如何使用single.php
文件已尝试创建single-jazz-clubs.php
和single-jazz-festival.php
但是现在single.php
继续加载父内容。
事实上我可以<?php get_template_part( \'content\', \'club\' ); ?>
从single.php
但是有没有办法确保它可以显示节日CPT,这个帖子属于那种帖子类型。
当前single.php
如下所示:
get_header(); ?>
<div id="content" class="large-8 columns" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( \'content\', get_post_format() ); ?>s
<nav class="nav-single">
<span class="nav-previous"><?php previous_post_link( \'%link\', \'<span class="meta-nav">\' . _x( \'«\', \'Previous post link\', \'wpforge\' ) . \'</span> %title\' ); ?></span>
<span class="nav-next"><?php next_post_link( \'%link\', \'%title <span class="meta-nav">\' . _x( \'»\', \'Next post link\', \'wpforge\' ) . \'</span>\' ); ?></span>
</nav><!-- .nav-single -->
<?php comments_template( \'\', true ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
以下是我的CPT:
function jazz_clubs() {
$labels = array(
\'name\' => _x( \'Jazz Clubs\', \'Post Type General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Jazz Club\', \'Post Type Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'Jazz Clubs\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Parent Jazz Clubs:\', \'text_domain\' ),
\'all_items\' => __( \'All Jazz Clubs\', \'text_domain\' ),
\'view_item\' => __( \'View Jazz Clubs\', \'text_domain\' ),
\'add_new_item\' => __( \'Add New Jazz Club\', \'text_domain\' ),
\'add_new\' => __( \'New Jazz Club\', \'text_domain\' ),
\'edit_item\' => __( \'Edit Jazz Club\', \'text_domain\' ),
\'update_item\' => __( \'Update Jazz Club\', \'text_domain\' ),
\'search_items\' => __( \'Search Jazz Club\', \'text_domain\' ),
\'not_found\' => __( \'No jazz club found\', \'text_domain\' ),
\'not_found_in_trash\' => __( \'No jazz clubs found in Trash\', \'text_domain\' ),
);
$args = array(
\'label\' => __( \'jazz club\', \'text_domain\' ),
\'description\' => __( \'Jazz Clubs around the world\', \'text_domain\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'comments\', \'trackbacks\', \'revisions\',\'post-formats\' ),
\'taxonomies\' => array( \'region\', \'country\', \'city\', \'state\', \'post_tag\' ),
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
\'menu_icon\' => \'/images/16-logo.png\', // 16px16
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'query_var\' => \'jazz clubs\',
\'capability_type\' => \'page\',
);
register_post_type( \'jazz clubs\', $args );
}
add_action( \'init\', \'jazz_clubs\', 0 );
?>
function jazz_festival() {
$labels = array(
\'name\' => _x( \'Jazz Festivals\', \'Post Type General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Jazz Festival\', \'Post Type Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'Jazz Festivals\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Parent Jazz Festivals:\', \'text_domain\' ),
\'all_items\' => __( \'All Jazz Festivals\', \'text_domain\' ),
\'view_item\' => __( \'View Jazz Festivals\', \'text_domain\' ),
\'add_new_item\' => __( \'Add New Jazz Festivals\', \'text_domain\' ),
\'add_new\' => __( \'New Jazz Festival\', \'text_domain\' ),
\'edit_item\' => __( \'Edit Jazz Festivals\', \'text_domain\' ),
\'update_item\' => __( \'Update Jazz Festival\', \'text_domain\' ),
\'search_items\' => __( \'Search Jazz Festival\', \'text_domain\' ),
\'not_found\' => __( \'No jazz festivals found\', \'text_domain\' ),
\'not_found_in_trash\' => __( \'No jazz festivals found in Trash\', \'text_domain\' ),
);
$args = array(
\'label\' => __( \'jazz festival\', \'text_domain\' ),
\'description\' => __( \'Jazz Festivals around the world\', \'text_domain\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'comments\', \'trackbacks\', \'revisions\', \'post-formats\', ),
\'taxonomies\' => array( \'region\', \'country\', \'city\', \'months\', \'musicians\', \'post_tag\'),
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
\'menu_icon\' => \'/images/16-logo.png\',
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'query_var\' => \'jazz festival\',
\'capability_type\' => \'page\',
);
register_post_type( \'jazz festival\', $args );
}
add_action( \'init\', \'jazz_festival\', 0 );
?>