以下函数可从插件启用单个自定义帖子类型模板:
function ch4_br_template_include( $template_path ) {
if ( get_post_type() == \'book_reviews\' ) {
if ( is_single() ) {
// checks if the file exists in the theme first,
// otherwise serve the file from the plugin
if ( $theme_file = locate_template( array
( \'single-book_reviews.php\' ) ) ) {
$template_path = $theme_file;
} else {
$template_path = plugin_dir_path( __FILE__ ) .
\'/single-book_reviews.php\';
} }
}
return $template_path;
}
显示自定义帖子类型列表的等效方法是什么?我想有一个单独的模板,用于在mysite/resellers上显示“分销商”的表格。
以下是我的自定义帖子类型:
public function wps_reseller_cpt() {
$labels = array(
\'name\' => _x( \'WPS Resellers\', \'post type general name\' ),
\'singular_name\' => _x( \'WPS Reseller\', \'post type singular name\' ),
\'add_new\' => _x( \'Add New\', \'book\' ),
\'add_new_item\' => __( \'Add New Reseller\' ),
\'edit_item\' => __( \'Edit Reseller\' ),
\'new_item\' => __( \'New Reseller\' ),
\'all_items\' => __( \'All Resellers\' ),
\'view_item\' => __( \'View Reseller\' ),
\'search_items\' => __( \'Search Resellers\' ),
\'not_found\' => __( \'No resellers found\' ),
\'not_found_in_trash\' => __( \'No Reseller found in the Trash\' ),
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Resellers\'
);
$args = array(
\'labels\' => $labels,
\'description\' => \'Holds our resellers and reseller specific data\',
\'public\' => true,
\'menu_position\' => 50,
\'supports\' => array( \'title\', \'editor\',\'image\', \'thumbnail\', \'custom-fields\' ),
\'rewrite\' => array(\'slug\' => \'resellers\'),
\'has_archive\' => true,
);
register_post_type( \'wps-reseller\', $args );
}