• Resolved fatty123

    (@fatty123)


    Just wondering is it possible or is there a cleaner way of displaying a custom post type displaying page without creating a page template. I not sure why I’m asking this but just feel like creating an empty template page to hold the custom post type sound a bit hacky to me.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You don’t *need* a template file for a custom post type to be displayed. If there’s no template file available then it will default back to the index.php template file in your theme. You can modify that to show things in a different way if it’s that post type if you like.

    Why do you feel that having a page template for a custom post type is a “hacky” way of doing things? Is there something specific that you want to do that this post type, or is it meant to be more generic?

    Thread Starter fatty123

    (@fatty123)

    Sorry I didn’t make myself clear enough, what I meant was whenever I created a custom post type (eg videos) and in order to display all the videos under my custom post type I need to create an empty page call mydomain.com/all-videos to display the posts. The reason I find this hacky is whenever I create a new custom post type I need to create a new empty page to hold the post type. Another disadvantage is that client has a tendency to either edit the slug or just delete the entire page, wouldn’t this be problematic?

    No, you do not need to create a new ‘page’ in the admin area to hold that. That would rightlyfully be a terrible way of doing things.

    When you’re registering your post type, set the option for has_archive to true, and then that post type will use a standard archive page to display the list. If you want to go hard-core, you can create two fies for it, archive-mypostslug.php and single-mypostslug.php and they will be used to display that post type instead of any other template files.

    Thread Starter fatty123

    (@fatty123)

    Thanks for the answer 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Create custom post type without creating a page template?’ is closed to new replies.