php - How to programatically create a simple HTML page using the permalink of another Wordpress post? -


i want create simple html page (not wordpress page) programmatically using permalink structure of existing post.

e.g. existing post www.example.com/this-is-example-post

i want create 3 more pages viz.

www.example.com/this-is-example-post/index1 www.example.com/this-is-example-postindex2 www.example.com/this-is-example-post/index3 

these urls need not real pages. need 3 different pages store different facebook meta. i'm building plugin. please guide. how can achieve it?

am thinking twisted? i'm going crazy thinking it. :( please help.

-------------edit---------------

after working on suggestions rahil, here's i'm now

<?php  add_action( 'init', 'xx_add_endpoint' );  function xx_add_endpoint() {     add_rewrite_endpoint( 'index', ep_permalink ); }  add_action( 'template_redirect', 'xx_render_endpoint' );  function xx_render_endpoint() {     if ( ! is_singular() or ! get_query_var( 'index' ) )     {         return;     }      // somthing here     exit; }   add_filter( 'request', 'xx_set_endpoint_var' );  function xx_set_endpoint_var( $vars ) {     isset( $vars['index'] ) , $vars['index'] = true;     return $vars; }  ?> 

but i'm trying understand how can pass variables request e.g. www.example.com/this-is-example-post/index/20/1, www.example.com/this-is-example-post/index/20/2, www.example.com/this-is-example-post/index/20/3 , on.

p.s. intend pass 2 values viz. /index/a/b a,b 2 values sent , handled under xx_render_endpoint function.

please guide.

ok here's how can it. remove template_redirect filter, don't have use this. instead use template_include filter (which proper way load alternate template)

see code comments explanation.

add_action( 'template_include', 'xx_render_endpoint');  function xx_render_endpoint($default_template) {     global $wp_query;      // if isn't singular page or index not endpoint     // return default template      if ( ! is_singular() || !isset($wp_query->query_vars['index']) )     {         return $default_template;     }      // our custom template selection variable default null     // or can set template "index" key     // like: plugin_dir_path(__file__) . '/your-template-index.php';      $template_selection = null;      // why we're exploding index value string array? said in comments     // key => value (index => 1/2). if have url     // "post-name/index/1/2", "1/2" value of key "index"     // have separate both values in case.      $indexes = explode('/', get_query_var('index'));      // assuming values "1/2" isset in url hold absolute path     // template on our $template_selection variable     // same second elseif block instead select value "1"      if (isset($indexes[0], $indexes[1])) {         $template_selection = plugin_dir_path(__file__) . '/your-template-1-2.php';     } else if (isset($indexes[0])) {         $template_selection = plugin_dir_path(__file__) . '/your-template-1.php';     }      // if our $template_selection variable not null assign value     // $default_template required parameter of template_include filter      if (isset($template_selection)) {         $default_template = $template_selection;     }      // fallback default template , our template selection     return $default_template; } 

note: need flush permalinks plus make sure permalink structure must pretty otherwise won't work.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -