当页面url和url产品类别相同时的优先页面url

时间:2019-07-18 03:50:54

标签: wordpress

当页面url和url产品类别相同时,优先页面url,

示例函数如下:

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' );

0 个答案:

没有答案