Basicly I want to indroduce a custom heirarchy with custom post types. I Would like it to be like this.
The Main Brands URL : http://localhost/brands/
which lists different types of Brands.
The personal Brand URL : http://localhost/brands/nike
which displays overview of brand "nike"
andlinks to different post types made by that particular Brand Account.
The Brand Gallery URL : http://localhost/brands/nike/gallery
which is the archive page for custom post type "Gallery"
.
The Gallery URL : 'http://localhost/brands/nike/gallery/posttitlewhich displays the custom post tupe
"gallery"`.
Similarly with custom post type "Information"
and "Brochure"
the links should be http://localhost/brands/nike/information/posttitle
and http://localhost/brands/nike/brochure/posttitle
.
I have Implemented the basic structure for permalink of custom post type but have not figured out how to develop the archive page.
I would like to know how to implement the acrhive page - http://localhost/brands/
and http://localhost/brands/nike
.
Below is the code for permalink of custom Post type "gallery"
.
add_action('init', 'tdd_add_rewrite_rules');
function tdd_add_rewrite_rules(){
global $wp_rewrite;
$wp_rewrite->add_rewrite_tag('%brand_name%', '([^/]+)', '');
$wp_rewrite->add_permastruct('gallery', '/brands/%brand_name%/gallery/%gallery%', false);
}
add_filter('post_type_link', 'tdd_permalinks', 10, 3);
function tdd_permalinks($permalink, $post, $leavename){
$no_data = get_the_author_meta('ID');;
$post_id = $post->ID;
if($post->post_type != 'gallery' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) return $permalink;
$var1 = get_the_author_meta('brand_name');
$var1 = sanitize_title($var1);
if(!$var1) { $var1 = $no_data; }
$permalink = str_replace('%brand_name%', $var1, $permalink);
return $permalink;
}
'has_archive' => true
set for archives to work. Then you make the templatearchive-posttype.php
where posttype is the name of the post type.http://localhost/gallery/[gallery_name]
and i want it in the form ofhttp://localhost/hotel/[hotel_name]/gallery/[gallery_name]
http://localhost/hotel/[hotel_name]
where[hotel_name]
is usermeta and is unique for each user.