我创建了一个自定义的帖子类型“Events”,并为其添加了categories函数。然而,类别仅显示在后端CMS中,我可以设置和添加新类别,但没有消息指示在前端网页中为事件设置的类别。
如何在前端网页中显示事件类别信息?
我复制了以下代码:
function enable_event_posttype() {
register_post_type( \'events\',
array(
\'labels\' => array(
\'name\' => __( \'Events\' ),
\'singular_name\' => __( \'Event\' ),
\'add_new\' => __( \'Add New Event\' ),
\'add_new_item\' => __( \'Add New Event\' ),
\'edit_item\' => __( \'Edit Event\' ),
\'new_item\' => __( \'Add New Event\' ),
\'view_item\' => __( \'View Event\' ),
\'search_items\' => __( \'Search Event\' ),
\'not_found\' => __( \'No events found\' ),
\'not_found_in_trash\' => __( \'No events found in trash\' )
),
\'public\' => true,
\'supports\' => array( \'title\', \'editor\', \'comments\'),
\'capability_type\' => \'post\',
\'rewrite\' => array("slug" => "events"), // Permalinks format
\'menu_icon\' => get_bloginfo(\'stylesheet_directory\') . \'/images/date.png\', // Icon Path
\'menu_position\' => \'5\'
)
);
}
add_action( \'init\', \'enable_event_posttype\' );
add_action( \'init\', \'build_taxonomies\', 0 );
function build_taxonomies() {
register_taxonomy( \'categories\', \'events\', array( \'hierarchical\' => true, \'label\' => \'Categories\', \'query_var\' => true, \'rewrite\' => true ) );
}