WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Post Types - confused (7 posts)

  1. trixienolix
    Member
    Posted 2 years ago #

    SO i'm trying to use Custom post types for a change so that I learn something new.
    I am completely stumped by a few things. Cany anyone clarify?

    I want to have a page with a list of my custom post types showing i.e. like the default category.php but for custom post types. I look on the codex and it says that the hierarchy for CPT is archive.php then index.php. So i add my loop to archive.php... how then do I view this list of CPT? What's the URL? If I view my individual CPT i see the url:
    http://www.website.com/custom-post-type-name/post-name/
    SO I want to access the page:
    http://www.website.com/custom-post-type-name
    that would list all my CPTs. However this page does not exist.

    Then i read that I need to add the loop to page.php... how come this is not listed in the template hierachy for CPTs?

    I think this shows my lack of understanding of CPTs. I want them to be a substitute for categories and posts I suppose but it looks as though they are not.

    Please can someone explain?!

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    you enable an archive, and give it a url, using has_archive

    http://codex.wordpress.org/Function_Reference/register_post_type
    look for has_archive here, you enable it when setting the CPT, you can then give it a slug, which will become your archive page for that CPT

    http://www.wpmods.com/wordpress-3-1-custom-post-type-archives/
    is also helpful

  3. trixienolix
    Member
    Posted 2 years ago #

    Blimey! It was that simple! Thank you, thank you...

    ANother quickie if anyone can help...
    On the WP menu admin page I have my CPT coming up with a list of the "posts" underneath that I can add to the menu.

    How can I get a list of the CPT archive pages here so people can easily add the http://www.website.com/custom-post-type-name archive listings to the menu (like you can with categories)?

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    Try to add the custom post type archive as a "custom link".

  5. trixienolix
    Member
    Posted 2 years ago #

    thanks keesiemeijer - yes I can do that, just wondering if there was a more user-friendly way than that. Not a big problem if not as custom links will do the job.

    One thing to note for anyone doing the has_archives code: mine didn't work for a while then I read about flushing permalinks... just go to your settings > permalinks page, change hte permalink structure to anything (default?), save, then change back to the one you want and sava gain - made it work for me

    Thanks everyone

  6. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    actually, I believe just visiting the permalinks page flushes them.... if not then hitting save definitely does, no need to actually change the settings.

    But definitely do remember to flush anytime you add a CPT (or custom taxonomy)

  7. trixienolix
    Member
    Posted 2 years ago #

    thanks rev voodoo.

Topic Closed

This topic has been closed to new replies.

About this Topic