我最终使用了end points. 这是我的最终(但简化)代码。在函数中,我添加了这个。
add_action(\'init\', \'jbenjaminsson_add_endpoints\');
function jbenjaminsson_add_endpoints()
{
add_rewrite_endpoint( \'files\', EP_PERMALINK );
add_rewrite_endpoint( \'participants\', EP_PERMALINK );
add_rewrite_endpoint( \'agenda\', EP_PERMALINK );
}
add_filter( \'request\', \'jbenjaminsson_filter_request\' );
function jbenjaminsson_filter_request( $vars )
{
if( isset( $vars[\'files\'] ) ) $vars[\'files\'] = true;
if( isset( $vars[\'participants\'] ) ) $vars[\'participants\'] = true;
if( isset( $vars[\'agenda\'] ) ) $vars[\'agenda\'] = true;
return $vars;
}
在模板上,我这样做了:
if ( get_query_var( \'files\' ) ) {
get_template_part( \'/template-parts/event\', \'files\' );
} elseif ( get_query_var( \'participants\' ) ) {
get_template_part( \'/template-parts/event\', \'participants\' );
} elseif ( get_query_var( \'agenda\' ) ) {
get_template_part( \'/template-parts/event\', \'agenda\' );
}