简体   繁体   中英

How to exclude author and date from page content query for Gatsby WordPress site

I'm making a Gatsby site that displays WordPress page content (Using WP plugins QP Gatsby and WPgraphQL) and I'm able to target most of the data that I need to populate my pages (titles, images etc) but I run into trouble when it comes to page content.

I use dangerouslySetInnerHtml to display the page content and sometimes the Gatsby site renders with the page author and date for the page above the paragraph text. Showing author and date is appropriate for blog posts but it's odd to see "by John Doe, June 2nd 2020" at the top of my About page. Sometimes the page content presents appropriately (without the author and date) and the pattern that I think I've observed is that the author and date appear after editing page content on the WordPress site while gatsby develop is running.

Is there a way to exclude author and date from the page content query? screenshot of page example

const IndexPage = ({ data }) => (
  <Layout>
    <article>
      {data.wpPage.featuredImage && (
        <figure>
          <Img
            fluid={data.wpPage.featuredImage.node.localFile.childImageSharp.fluid}
            alt={data.wpPage.featuredImage.node.altText}
          />
        </figure>
      )}
      <div dangerouslySetInnerHTML={{ __html: data.wpPage.content }} />
    </article>
  </Layout>
)

export const query = graphql`
  query HomePageQuery {
    wpPage(uri: {eq: "/"}) {
      id
      title
      content
      featuredImage {
        node {
          localFile {
            childImageSharp {
              fluid(maxWidth: 1360) {
                ...GatsbyImageSharpFluid
              }
            }
          }
          altText
        }
      }
    }
  }
`

This happens when you've updated the database from the WP end with gatsby develop still running.

If you interrupt and restart gatsby develop , the dangerouslySetInnerHTML contents should present correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM