WordPress的组织方式是为锦标赛、游戏和参与者创建单独的帖子类型。
下面是tournament
岗位类型注册:
add_action( \'wp_loaded\', function() {
register_post_type(
\'tournament\',
[
\'label\' => __( \'Tournaments\', \'tournaments\' ),
\'labels\' => [
\'name\' => __( \'Tournaments\', \'tournaments\' ),
\'singular_name\' => __( \'Tournament\', \'tournaments\' ),
\'add_new\' => __( \'Add New\', \'tournaments\' ),
\'add_new_item\' => __( \'Add New Tournament\', \'tournaments\' ),
\'edit_item\' => __( \'Edit Tournament\', \'tournaments\' ),
\'new_item\' => __( \'New Tournament\', \'tournaments\' ),
\'view_item\' => __( \'View Tournament\', \'tournaments\' ),
\'view_items\' => __( \'View Tournaments\', \'tournaments\' ),
\'search_items\' => __( \'Search Tournaments\', \'tournaments\' ),
\'not_found\' => __( \'No tournaments found.\', \'tournaments\' ),
\'not_found_in_trash\' => __( \'No tournaments found in Trash.\', \'tournaments\' ),
\'parent_item_colon\' => __( \'Parent Tournament:\', \'tournaments\' ),
\'all_items\' => __( \'All Tournaments\', \'tournaments\' ),
\'archives\' => __( \'Tournament Archives\', \'tournaments\' ),
\'attributes\' => __( \'Tournament Attributes\', \'tournaments\' ),
\'insert_into_item\' => __( \'Insert into tournament\', \'tournaments\' ),
\'uploaded_to_this_item\' => __( \'Uploaded to this tournament\', \'tournaments\' ),
\'featured_image\' => __( \'Banner\', \'tournaments\' ),
\'set_featured_image\' => __( \'Set banner\', \'tournaments\' ),
\'remove_featured_image\' => __( \'Remove banner\', \'tournaments\' ),
\'use_featured_image\' => __( \'Use as banner\', \'tournaments\' ),
\'filter_items_list\' => __( \'Filter tournaments list\', \'tournaments\' ),
\'items_list_navigation\' => __( \'Tournaments list navigation\', \'tournaments\' ),
\'items_list\' => __( \'Tournaments list\', \'tournaments\' ),
],
\'public\' => TRUE,
\'hierarchical\' =>TRUE,
/*
* \'edit_post\' is now \'edit_tournament\'
* \'edit_posts\' is now \'edit_tournaments\'
* Use these caabilities to set custom user capabilities, maybe
* depending on the user role.
*/
\'capability_type\' => [ \'tournament\', \'tournaments\' ],
\'map_meta_cap\' => TRUE,
\'supports\' => [
\'title\',
\'editor\',
\'comments\',
\'revisions\',
\'author\',
\'excerpt\',
\'page-attributes\', // allows multiple custom tournament templates
\'thumbnail\',
\'custom-fields\'
],
\'has_archive\' => __( \'tournaments\', \'tournaments\' ),
\'rewrite\' => [
\'slug\' => __( \'tournament\', \'tournaments\' ),
],
\'delete_with_user\' => FALSE,
]
);
});
正如您所看到的,您可以为该帖子类型使用一些内置功能,例如为横幅使用特色图像。您还可以将此帖子类型分层,以便为定期锦标赛提供“父”页面,并为每年或每月实例提供单独的页面。
我现在还要设置games
和players
以类似的方式发布类型(当然不是层次结构)。然后,我将为允许添加或编辑锦标赛的用户注册一个自定义用户角色。
对于概述页面,请使用存档模板,在这种情况下archive-tournament.php
. 请参见Template Hierarchy 了解更多信息。您可以在此处轻松构建一个表,而不是通常的帖子列表。在每个锦标赛页面上(single-tournament.php
), 你可以列出游戏和玩家、开始和结束时间、价格等等。对于这些数据,请使用锦标赛编辑器页面上的自定义元框。
这只是一个原始的概念。实际实施需要一段时间。确保手动编写代码,不要使用一些“神奇的”post类型UI插件!原因是您很可能需要随着时间的推移调整此代码;你应该通晓每一行。