【发布时间】:2019-08-18 18:33:24
【问题描述】:
我有一个 Gatsby 网站,它正在从另一个 Wordpress 网站提取数据。它可以为帖子动态创建页面,但是一旦我添加了新的自定义帖子类型,它只会为这个创建页面,而不是帖子。所以基本上,它只为我添加到“gatsby-node.js”文件的最新帖子创建页面。看起来像这样:
const path = require(`path`)
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
return graphql(`
{
allWordpressPost(sort: { fields: [date] }) {
edges {
node {
title
excerpt
content
slug
}
}
}
}
`).then(result => {
result.data.allWordpressPost.edges.forEach(({ node }) => {
createPage({
path: node.slug,
component: path.resolve(`./src/templates/blog-post.js`),
context: {
// This is the $slug variable
// passed to blog-post.js
slug: node.slug
},
})
})
})
}
//Create a page for each Property Post type
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
return graphql(`
{
allWordpressWpProperty {
edges {
node {
slug
title
content
featured_media {
localFile {
childImageSharp {
original {
width
height
src
}
}
}
}
acf {
size
}
}
}
}
}
`).then(result => {
result.data.allWordpressWpProperty.edges.forEach(({ node }) => {
createPage({
path: node.slug,
component: path.resolve(`./src/templates/property.js`),
context: {
// This is the $slug variable
// passed to property.js
slug: node.slug
},
})
})
})
}
当我尝试访问博客文章时,我得到的错误是“无法读取未定义的“页面”。有没有办法为两者创建页面?
【问题讨论】:
标签: wordpress gatsby wordpress-rest-api