你可以钩住parse_request
并欺骗WordPress,使其认为它与一个页面永久链接相匹配,如果存在一个类别术语具有相同的slug:
/**
* Override query for pages that match a category slug.
*
* @param WP $wp
*/
function wpse_177014_category_to_page ( $wp ) {
if ( ! empty( $wp->query_vars[\'category_name\'] ) && get_page_by_path( $slug = $wp->query_vars[\'category_name\'] ) ) {
if ( ! empty( $wp->query_vars[\'paged\'] ) )
$page = $wp->query_vars[\'paged\'];
else
$page = \'\';
$wp->matched_query = "pagename=$slug&page=$page";
$wp->query_vars = array(
\'pagename\' => $slug,
\'page\' => $page,
);
}
}
add_action( \'parse_request\', \'wpse_177014_category_to_page\' );