Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dynamic pages with GatsbyJS
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const wpData = await graphql(`
{
allWordpressPost {
nodes {
wordpress_id
slug
title
content
author {
name
}
}
}
}
`)
if (wpData.errors) {
console.error(wpData.errors)
}
const { allWordpressPost } = wpData.data
allWordpressPost.nodes.forEach( post => {
createPage({
path: `/${post.slug}`,
component: require.resolve(`./src/templates/post.js`),
context: { post },
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.