没有重定向的wordpress动态网址

wordpress dynamic urls witout redirect

我需要创建动态 urls 所有加载相同页面(请注意加载而不是重定向)我只能找到重定向的插件。基本上我需要的是:

/somepage/something
/somepage/anotherthig
/somepage/thething/morethings

全部加载现有页面

/somepage

但必须保留原始 url(不是重定向)。非常感谢任何关于如何做到这一点的建议(如果你知道一个插件,也可以做到这一点)。

您可以使用此插件创建动态 url。这个插件是免费的。

https://wordpress.org/plugins/sdk-wp-dynamic-url/

如果您正在寻找一些先进的东西那么这个插件肯定会为您做,但它是付费的:

https://wordpress.org/plugins/if-so/

希望对您有所帮助

快乐编码

应该没有那么难,可以通过修改$wp_query$post全局变量来实现,

试试这个代码

// modify variable by hooking it on 'wp' action
add_action( 'wp', function() {

    global $wp, $wp_query, $post; //define global variable
    //include $wp variable so you can check the url request

    // list the url you want to use
    $dynamic_url = [
        'somepage/something',
        'somepage/anotherthig',
        'somepage/thething/morethings'
    ];


    // check if page request is found from the array above
    if ( in_array( $wp->request, $dynamic_url ) ) {

        // build query argument
        $args=[
            'post_type' => 'page', //assuming its a page
            'p' =>  26 // page ID of the page you want to display on those dynamic URLS
        ];

        // run the query and assign it to $wp_query global variable
        $wp_query = new WP_Query( $args ); 

        // modify is_single wp_query param and tell it its not a post
        $wp_query->is_single = '';

        // modify is_page wp_query param and tell it its a page
        $wp_query->is_page = 1;

        //assign  (1st) found post to global post variable
        $post = $wp_query->posts[0];

        //modify header as 202 status (unless you want these pages to stay as 404), by defualt its a 404
        status_header( 202 );

        //done
    }

});