From 2249ea842a18e4da39c6e3abcf8eeabd78a17116 Mon Sep 17 00:00:00 2001 From: Mark Sta Ana Date: Tue, 1 Jan 2019 13:29:29 +0000 Subject: [PATCH] Create an index of WordPress posts --- src/pages/index.js | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/pages/index.js b/src/pages/index.js index e8f1c9a..8f6c843 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -1,21 +1,41 @@ import React from 'react' -import { Link } from 'gatsby' +import { Link, graphql } from 'gatsby' import Layout from '../components/layout' -import Image from '../components/image' import SEO from '../components/seo' -const IndexPage = () => ( +const IndexPage = ({data}) => ( -

Hi people

-

Welcome to your new Gatsby site.

-

Now go build something great.

-
- -
- Go to page 2 +

Welcome to the Gatsby demo

+

There are {data.allWordpressPost.totalCount} posts

+ {data.allWordpressPost.edges.map(({ node }) => ( +
+ +

- {node.date}

+ + +
+
+ ))} ) export default IndexPage + +export const pageQuery = graphql` + query { + allWordpressPost(sort: { fields: [date], order: DESC }) { + totalCount + edges { + node { + id + title + excerpt + slug + date(formatString: "Do MMMM") + } + } + } + } +`