query PostsWithFeaturedImage {
allWordpressPost {
nodes {
title
featured_media {
title
caption
description
alt_text
source_url
}
}
}
}
The key description
has HTML you could print to the DOM to have an image tag. Or source_url
and alt_text
could be used with an image tag.
Use sharp to create fixed arguments
query PostsWithFeaturedImage {
allWordpressPost {
nodes {
title
featured_media {
title
caption
alt_text
source_url
localFile {
childImageSharp {
fixed(width: 500, height: 300) {
src
srcSet,
srcSetWebp
}
}
}
}
}
}
}
Final Query with everything I need from posts:
{
allWordpressPost {
nodes {
title
featured_media {
title
caption
alt_text
source_url
localFile {
childImageSharp {
fixed(width: 500, height: 300) {
src
srcSet
srcSetWebp
height
width
base64
tracedSVG
srcWebp
srcSetWebp
}
}
}
}
}
}
}
export const pageQuery = graphql`
fragment PostListFields on wordpress__POST {
id
title
excerpt
author {
name
slug
avatar_urls {
wordpress_48
}
}
date(formatString: "MMMM DD, YYYY")
slug
featured_media {
title
caption
alt_text
source_url
localFile {
childImageSharp {
fixed(width: 500, height: 300) {
src
srcSet
srcSetWebp
height
width
base64
tracedSVG
srcWebp
srcSetWebp
}
}
}
}
}
`
Fixed and fluid:
{
allWordpressPost(limit: 1) {
nodes {
title
date(formatString: "MMMM DD, YYYY")
featured_media {
localFile {
childImageSharp {
fluid(maxWidth: 1200, maxHeight: 300) {
src
sizes
srcSet
srcWebp
srcSetWebp
tracedSVG
aspectRatio
presentationWidth
presentationHeight
base64
}
fixed(width: 500, height: 300) {
src
srcSet
srcSetWebp
height
width
base64
tracedSVG
srcWebp
srcSetWebp
}
}
}
}
}
}
}