【发布时间】:2020-05-29 04:19:48
【问题描述】:
我有许多基于不同篮球联赛的类别League A, League B, League C 等等。我想做的是让每个联赛为每个赛季都有一个自定义分类2006-2007,2007-2008,2008-2009,这样我就可以只显示那个赛季的帖子Category: League A -> Season: 2006-2007 -> Posts。
到目前为止,我已经为 post 帖子类型创建了以下分类:
add_action( 'init', 'create_seasons' );
function create_seasons() {
$labels = array(
'name' => 'Seasons',
'singular_name' => 'Season',
'search_items' => 'Search Seasons',
'all_items' => 'All Seasons',
'edit_item' => 'Edit Season',
'update_item' => 'Update Season',
'add_new_item' => 'Add New Season',
'new_item_name' => 'New Season Name',
'menu_name' => 'Seasons',
'view_item' => 'View Season',
'popular_items' => 'Popular Season',
'separate_items_with_commas' => 'Separate Season with commas',
'add_or_remove_items' => 'Add or remove Season',
'choose_from_most_used' => 'Choose from the most used seasons',
'not_found' => 'No seasons found'
);
register_taxonomy(
'seasons',
'post',
array(
'label' => __( 'Season' ),
'hierarchical' => false,
'labels' => $labels,
'public' => true,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
'show_admin_column' => true,
'rewrite' => array(
'slug' => 'seasons'
)
)
);
}
现在,如果我想在季节分类 2008-2009 期间显示类别 League A 的所有帖子,我可以使用 URL 参数 ?seasons=2008-2009。完整网址http://localhost/site/category/league-a/?seasons=2008-2009
困扰我的是,我想默认显示当前季节的帖子2019-2020,而不使用每个类别的 URL 参数?seasons=2019-2020。
示例:
http://localhost/site/category/league-a/ -> Show posts from seasons taxonomy 2019-2020 only。
有没有办法让它工作?重写规则?
您还认为我的方法对我正在尝试做的事情是正确的吗?
谢谢
【问题讨论】:
标签: php wordpress url-rewriting