Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to display single post? #2

Closed
sangdth opened this issue Oct 17, 2017 · 3 comments
Closed

How to display single post? #2

sangdth opened this issue Oct 17, 2017 · 3 comments

Comments

@sangdth
Copy link

sangdth commented Oct 17, 2017

Hi Evan,

I'm trying to display single post, I've created a SinglePost.vue, add object into /router/index.js

{
    // How to dynamic detect the path?
    path: '/:slug',
    component: SinglePost
}

Right now I'm cheating, he he, change the permalink into "postname" only, to make it easy.

My question is, in WP we have many ways to display the path, from date /2017/10/18/hello-world, to category like /cagegory/hello-world, how could we get it and put it into the path programmatically?

Thanks.

@EvanAgee
Copy link
Owner

EvanAgee commented Oct 17, 2017

Hey @sangdth here's how I would do it.

For each post you're going to get the slug as part of the post object. For your link to that post you'll want to do a <router-link :to="'/posts/'+post.slug"></router-link>

Then in your router you would do:

{
    // How to dynamic detect the path?
    path: '/posts/:slug',
    component: SinglePost
}

One of the costs of replacing the WordPress theme with a Vue app is that we lose access to some of those handy WordPress functions, unless of course we leverage those to modify the JSON response from the API.

@sangdth
Copy link
Author

sangdth commented Oct 18, 2017

Thanks, it works.

@sangdth sangdth closed this as completed Oct 18, 2017
@EvanAgee
Copy link
Owner

Awesome, feel free to open a PR if you think your changes might be beneficial to the project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants