I have a website that has many different custom type posts. I want to use pages as parent templates for those custom type posts (listing all particular custom posts)
For example I have a page called "Blog" and it has URL www.mysite.com/blog It will list custom posts called "blog". Following is the custom post type implementation:
$args = array (
'label' => 'Blog Posts',
'singular_label' => 'Blog Post',
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'blog'),
'query_var' => true,
'menu_icon' => null,
'menu_position' => 2,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'post-formats', 'custom-fields', 'editors')
);
register_post_type( 'blog' , $args );
This works and each I can click and view each blog posts with URL www.mysite.com/blog/hi-this-is-a-post
However, pagination is broken. www.mysite.com/blog/page/2/
returns 404. I found a workaround by appending /post/ to the URL of the custom post like
'rewrite' => array('slug' => 'blog/post'),
This doesn't break pagination nor link to posts but this is not what we want. We want to have URL that's like
www.mysite.com/blog/each-post
Can someone please give me clue? Thanks.
/page/
, it's just/blog/2/
. you could add a rewrite rule to handle it, but a simpler way is to register the post type withhas_archive
and use that instead of a parent page.