- This topic is empty.
-
AuthorPosts
-
September 8, 2014 at 1:04 am #182103
[email protected]
ParticipantHello everyone,
I am working on a wordpress project and to make the CMS more organised, I am using custom post types.
Main pages:
1. Home
2. Articles
3. Products
4. Resources
5. Videos
6. Contact- Home and 6. Contact pages are just simple pages but except those two , Articles, products, Resources, Videos are like blog. Each page will have different blog template (All items/articles listed) and different Single page template (To show whole item/article).
According to WP template hierarchy I though i could name different blog page template like Page-custm_post_type_name.php (page-article.php, page-videos.php) and they will work as my blog page and for single page like single-articles.php but it didn’t work for me.
All the custom blog pages fall back to index.php even if the page-post_type_name.php is available. No idea what i am doing wrong.
The solution above works good for pages but not for blog pages (list of articles).
Thank you,September 8, 2014 at 4:48 am #182117Alen
ParticipantIf you look at WordPress Template Hierarchy for custom post type you’ll see it’s using
archive-{post_type}.php
.Also, don’t create custom post type for everything, that doesn’t make sense.
- Home, should be a page
- Articles, should be posts
- Products, should be custom post type
- Resources, should be a page
- Videos, could be custom post type
- Contact, should be a page
You can also create specific templates for your pages.
September 8, 2014 at 7:58 pm #182299[email protected]
ParticipantThank you @Alen. I created archive-{post-type}.php instead of page-{post-type}.php and it’s now working as I was looking for.
Now all the custom posts i created have the blog page and i also created single page for them like so, single-{post-type}.php.
Single page is working as expected for 3 custom post types but not for one and i am sure that i did exactly the same thing to create the single page for all of them.
If the post name is product, blog page is archive-product.php and single page is single-product.php then from archive-product.php it should go to single-product.php by default, right? but its not happening here.
Again, not sure whats going on.
Thanks,
September 8, 2014 at 9:07 pm #182301Alen
ParticipantIn the code for the custom post type do you have
'has_archive' => true
?September 8, 2014 at 9:12 pm #182302[email protected]
ParticipantYes
September 23, 2014 at 8:46 pm #184409[email protected]
ParticipantThere was nothing wrong with the code, it was just a url caching issue.
I Had to reset the permalinks in WP dashboard -> settings -> permalinks
1. Reset it to Default and save then,
2. set it to whatever you want.For anyone who is this facing this issue.
Thanks @Alen you were very helpful.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.