• Resolved leticia

    (@leticia5959)


    Hello

    In frontend, I want let users to see extra data for posts in a different page.

    I want to access this new page as follow:

    if the URL of a post is: <domain site>/postname
    the URL to see the extra data is: <domain site>/postname/specialdata

    I already has a plugin with a page that receive the post name and return that extra data.

    My doubt is how is recommended to associate the URL <domain site>/postname/specialdata with the plugin php page that show the extra post data.

    Any comment is appreciated.
    Thanks
    Leticia

Viewing 1 replies (of 1 total)
  • Thread Starter leticia

    (@leticia5959)

    Hi

    Here is how I solve my problem:

    // Creating rewrite rules and query variables
    add_filter('query_vars', 'handle_query_vars');
    add_filter('rewrite_rules_array', 'handle_rewrite_rules_array');
    // Flush the rewrite rules
    add_action('init', 'handle_flush_rewrite');
    // Add filter to show template
    add_filter('home_template', 'handle_home_template');
    
    function handle_rewrite_rules_array($rules) {
        $newrules['.*/images$'] = 'index.php?showimages=1';
    
        $newrules = array_merge($newrules,$rules);
        return $newrules;
    }
    
    function handle_query_vars ( $vars ) {
        $vars[] = "showimages";
        return $vars;
    }
    
    // Function to change the home template
    function handle_home_template($template_dir) {
        if (get_query_var("showimages"))
    	'dir_to_page/custom_page.php';
        else
    	return $template_dir;
    }
    
    function handle_flush_rewrite() {
        global $wp_rewrite;
        $wp_rewrite->flush_rules();
    }

    Regards

Viewing 1 replies (of 1 total)
  • The topic ‘associate a post url with extra data’ is closed to new replies.