交个朋友,长个技能🥎🤸🏼‍♂️

wordpress

wordpress rest api 寻找分类为8的文章,微信小程序代码如何写

微信小程序中可以使用wx.request()方法来调用WordPress REST API。以下是一个简单的示例,用于获取分类为8的所有文章:

// pages/index/index.js
Page({
  data: {
    articles: [],
  },

  onLoad: function () {
    const that = this;
    wx.request({
      url: 'https://your-wordpress-site.com/wp-json/wp/v2/posts?categories=8', // 替换为你的WordPress站点地址和API路径
      method: 'GET',
      header: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer YOUR_ACCESS_TOKEN' // 替换为你的访问令牌(如果有)
      },
      success: function (res) {
        that.setData({
          articles: res.data,
        });
      },
      fail: function (err) {
        console.error('请求失败:', err);
      }
    });
  }
});

注意:请将上述代码中的https://your-wordpress-site.com/wp-json/wp/v2/posts?categories=8替换为你的WordPress站点地址和API路径,以及将YOUR_ACCESS_TOKEN替换为你的访问令牌(如果有)。

关于分类位置在哪里看?

当用鼠标指向二的位置时,地址栏里面会有数字

发表评论