Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress custom post types

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #182103
    [email protected]
    Participant

    Hello 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

    1. 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,

    #182117
    Alen
    Participant

    If 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.

    #182299
    [email protected]
    Participant

    Thank 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,

    #182301
    Alen
    Participant

    In the code for the custom post type do you have 'has_archive' => true?

    #182302
    [email protected]
    Participant

    Yes

    #184409
    [email protected]
    Participant

    There 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.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.