bshiluk / vue-wordpress

Use Vue.js and the WP REST API to build WordPress themes as SPAs with dynamic routing, HMR for development, SEO enabled, and SSR capable. Demo:
http://vue-wordpress-demo.bshiluk.com
491 stars 112 forks source link

How to make custom post types work #3

Closed shubhra14 closed 5 years ago

shubhra14 commented 5 years ago

Hi,

How do I make custom post types work with this theme? I would really appreciate a bit of guidance.

Thank you

bshiluk commented 5 years ago

Is there somewhere specifically you're stuck?

Basically it would go something like:

  1. Make sure when you register your custom post type you enable REST API support 'show_in_rest' => true
  2. Initialize the RADL plugin with your custom post type endpoint 'custom_post_type' => RADL::endpoint( 'custom_post_type' )
  3. Create a component for your custom post type
  4. Add a route to routes.js that uses your custom component along with a path like /custom_post_type
  5. Create a customposttype-archive.php template ( can pretty much just look like index.php until you want to start rendering server side, but it's needed because WP will want to render archive.php which won't work with how the templates and components are currently structured )
  6. Create a single view by repeating 3-5, except your path would be /custom_post_type/${slug} and your template would be customposttype-single.php

There are different ways you can do it, but that's a general gist. You'll probably need to have a good idea of what's going on before you can start extending it effectively.

shubhra14 commented 5 years ago

Hi, thank you for taking the time to respond.

I have done 1. & 2.

Can you elaborate a bit on the 3rd step? Do I need to duplicate+rename files in the src > components?

return {
      request: {
        type: 'posts',   <--edit this?
        slug: this.slug,
        showLoading: true }
    }

I am sorry if these are silly questions.

Edit: I was able to make it work. I want to thank you for helping me out

bshiluk commented 5 years ago

Not a problem at all. Glad you got it working