I would like to know if is possible to add a "subpage" to a post and in this "subpage" have paginated content, for example:
I Have a Post Lorem Ipsum
This post has Videos, Photos and Audios as attachments
When you access the post www.website.com/lorem-ipsum/ you access basically just the text, and some other infos and you could access:
- www.website.com/lorem-ipsum/videos/
- www.website.com/lorem-ipsum/videos/page/2
- www.website.com/lorem-ipsum/audios/
- www.website.com/lorem-ipsum/audios/page/2
- www.website.com/lorem-ipsum/photos/
- www.website.com/lorem-ipsum/photos/page/2
I have this on my functions.php
<?php
add_action( 'after_setup_theme', 'rm_setup_theme' );
function rm_setup_theme() {
add_filter( 'rewrite_rules_array', 'rm_custom_rules' );
add_filter( 'query_vars', 'rm_custom_vars' );
add_filter( 'template_redirect', 'rm_custom_redirect' );
}
function rm_custom_rules( $rules ) {
$r = array(
'([^/]+)(/[0-9]+)?/photos/page/?([0-9]{1,})/?$' => 'index.php?name=$matches[1]&paged=$matches[2]&photos=1',
'([^/]+)(/[0-9]+)?/photos/?$' => 'index.php?name=$matches[1]&photos=1'
);
return array_merge( $r, $rules );
}
function rm_custom_vars( $qv ) {
array_push( $qv, 'photos' );
return $qv;
}
function rm_custom_redirect( ) {
global $wp_query;
$f = $wp_query->get( 'photos' );
if ( $f ) {
require TEMPLATEPATH . '/content-photos.php';
exit;
}
}
?>
With this I have the following urls "working":
- www.website.com/lorem-ipsum/photos/
- www.website.com/lorem-ipsum/photos/page/2
But the pagination it's not working, it looks like the paged var it's not passed, it always show the content of the first page, no matter what page do you type in the address bar
/photos Request
The request on photos page (www.website.com/lorem-ipsum/photos/):
Request:
lorem-ipsum-dolor-sit-amet/photos
Query String:
name=lorem-ipsum-dolor-sit-amet&photos=1
Matched Rewrite Rule:
([^/]+)(/[0-9]+)?/photos/?$
Matched Rewrite Query:
name=lorem-ipsum-dolor-sit-amet&photos=1
/photos/page/2 Request
The request on photos page (www.website.com/lorem-ipsum/photos/page/2):
Request:
lorem-ipsum-dolor-sit-amet/photos/page/2
Query String:
name=lorem-ipsum-dolor-sit-amet&photos=1
Matched Rewrite Rule:
([^/]+)(/[0-9]+)?/photos/page/?([0-9]{1,})/?$
Matched Rewrite Query:
name=lorem-ipsum-dolor-sit-amet&paged=&photos=1
Thanks