0

I am wondering if it's possible to have a page, let's say called 'books' with some listed books.

Next to this normal page we create an custom post named 'books' were we collect our books.

Nou I already have the url domain.com/books/ with the overview of all my books, I am wondering how I need to configure the custom post to use this page as parent to generate an url as domain.com/books/the-title-of-the-book/

Thank you!

  • To clarify, do you want posts of a custom post type to have a manually created page as their parent? As opposed to an automatically created archive that lists posts of post type 'book'? – kittsville Nov 7 '15 at 16:00
  • Yes, what I actually want is /book (page)/%slug%(custom_post_type) – Freshtea Nov 7 '15 at 16:05
  • Thanks for clarifying that. I had to fiddle with permalinks for some time for my library plugin WP-Librarian, so I think I know the answer. I'll just check if it works. – kittsville Nov 7 '15 at 16:13
2

If you want your custom post type listed under a page you can add the permalink of the page to the rewrite slug like so:

register_post_type('my_books', array(
'has_archive' => false,                 // Stops domain.com/book becoming the cpt's archive
'rewrite'     => array('slug' => 'book')
));

You need to visit Settings->Permalinks after making any changes to permalinks to re-generate them. You should now be able to visit books under mysite.com/book/my-book-slug and visit your manually created Page under mysite.com/book.

  • Works m8! The only thing is that it points at my index.php now. I didn't reserve this page for the index as the index has been pointed to a page-hone.php, could you think about any reasons for this? – Freshtea Nov 7 '15 at 17:44
  • Not too sure what's causing that, when I tested that setup on my dev server it worked. If you tried other things first and left the code in then it may be interfearing. – kittsville Nov 8 '15 at 19:48
  • fixed it out, I created a page 'books' instead of page-books and this was the trick :) – Freshtea Nov 8 '15 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.