I created a new custom type called 'books' and I created a Field using the Advanced Custom Fields plugin where I define the fields and create the records, with post names such as book1, book2, etc. I want to define a view for the elements of this particular custom type so when the visitor goes to website/books/book1 I will display information about book1. I tried defining single-books.php at the root of the theme but it didn't work. How can I define a template for the posts of a custom post?
Thanks
I created a new custom type called 'books' and I created a Field using the Advanced Custom Fields plugin where I define the fields and create the records, with post names such as book1, book2, etc. I want to define a view for the elements of this particular custom type so when the visitor goes to website/books/book1 I will display information about book1. I tried defining single-books.php at the root of the theme but it didn't work. How can I define a template for the posts of a custom post?
Thanks
Share Improve this question asked May 22, 2019 at 16:32 GonzaloGonzalo 1672 silver badges10 bronze badges 5 |1 Answer
Reset to default 1You can Use single-{posttype}.php for the single template.
And, if you have register your post type with the has_archive argument set to true, then you can use archive-{posttype}.php for your archive template.
You can check Template Hierarchy
Also for 404 Page, double check that page slug and post-type slug is NOT SAME. I mean check whether you have created any page with slug "books".
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745470409a4629106.html
single-books.php
would be correct for a CPT namedbooks
. However you may want to double-check your code and adjust so the name isbook
singular. When you say you added the file and it "didn't work," what happened? Did you confirm that a different template was being used? – WebElaine Commented May 22, 2019 at 17:07example/books/book1
- it relies on having an actual post with the slug "book1". – WebElaine Commented May 22, 2019 at 17:09