【问题标题】:Wordpress API: How do I get post by category with vue js on laravelWordpress API:如何在 laravel 上使用 vue js 按类别发布帖子
【发布时间】:2019-02-27 07:43:51
【问题描述】:

我在前端使用 laravel 和 vue js 并在后端使用 wp rest api 构建一个 cms 系统。所以我有新闻类别作为帖子,我只希望新闻类别出现在我的页面中,怎么做,因为现在我从所有类别中获取所有帖子?有可能吗,这是我的vue js代码来获取所有帖子

    <script>
import sanitizeHtml from 'sanitize-html'
export default {
    created(){
        axios.get('http://localhost/newlara/main/public/wp/wp-json/wp/v2/posts?per_page=9')
        .then(response => {
            //console.log(response);
            this.posts = response.data
        })
    },
    data(){
        return{
            posts: []
        }
    },
     methods: {
        stripTags(html) {
            return sanitizeHtml(html, {
                allowedTags: []
            }).substring(0, html.indexOf('&hellip;'))
        }
    }
};
</script>

希望你能帮助我,谢谢。

【问题讨论】:

  • 您想从后端加载所有帖子并在前端拆分它们吗?
  • 我想从我用 wordpress 制作的类别中加载帖子,我有新闻类别。现在从我的代码中,我可以从 wordpress 后端加载我的所有帖子

标签: php json wordpress laravel vue.js


【解决方案1】:

您可以通过

获取特定类别的帖子
 http://demo.wp-api.org/wp-json/wp/v2/categories/<id>

在这里查看文档

https://v2.wp-api.org/reference/categories/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 2018-05-18
    • 1970-01-01
    • 2021-10-26
    相关资源
    最近更新 更多