我正在创建一个插件,其中我创建了一个自定义帖子类型的智能事件,我想通过一个页面为该类别下的单个帖子提供服务。这就是为什么我创建了一个名为:single-event.php
直接进入插件文件夹-类似-event > single-event.php
我用这个函数来加载单个页面
function myevent($template) {
if (\'event\' == get_post_type(get_queried_object_id()) && !$template) {
$template = dirname(__FILE__) . \'/single-event.php\';
}
return $template;
}
add_action( \'single_template\', \'myevent\'));
但这篇文章是在主题单曲中展示的。php页面不在我创建的页面中。
下面是我的CPT寄存器代码,我在permalink设置中刷新了重写模式。
function eventCPT(){
$labels = array(
\'name\' => esc_html__( \'Events\', \'event\' ),
\'singular_name\' => esc_html__( \'Event\', \'event\' ),
\'menu_name\' => esc_html__( \'Event\', \'event\' ),
\'name_admin_bar\' => esc_html__( \'Event\', \'event\' ),
\'add_new\' => esc_html__( \'Add New Event\', \'event\' ),
\'add_new_item\' => esc_html__( \'Add New Event\', \'event\' ),
\'new_item\' => esc_html__( \'New Event\', \'event\' ),
\'edit_item\' => esc_html__( \'Edit Event\', \'event\' ),
\'view_item\' => esc_html__( \'View Event\', \'event\' ),
\'all_items\' => esc_html__( \'All Events\', \'event\' ),
\'search_items\' => esc_html__( \'Search Events\', \'event\' ),
\'parent_item_colon\' => esc_html__( \'Parent Events:\', \'event\' ),
\'not_found\' => esc_html__( \'No events found.\', \'event\' ),
\'not_found_in_trash\' => esc_html__( \'No events found in Trash.\',\'event\' )
);
$args = array(
\'labels\' => $labels,
\'description\' => __( \'Description.\', \'event\' ),
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'event\' ),
\'capability_type\' => \'post\',
\'has_archive\' => false,
\'hierarchical\' => false,
\'menu_position\' => null,
\'menu_icon\' => \'dashicons-calendar-alt\',
\'supports\' => array( \'title\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
);
register_post_type( \'event\', $args );
}
add_action( \'init\', \'eventCPT\'));