Created
January 24, 2023 13:45
-
-
Save JEverhart383/48da4682e6125525570cbaec66c41539 to your computer and use it in GitHub Desktop.
Faust Custom Template Registration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { gql } from '@apollo/client'; | |
import * as MENUS from '../constants/menus'; | |
import { BlogInfoFragment } from '../fragments/GeneralSettings'; | |
import { | |
Header, | |
Footer, | |
Main, | |
Container, | |
EntryHeader, | |
NavigationMenu, | |
Post, | |
FeaturedImage, | |
SEO, | |
} from '../components'; | |
export default function Component(props) { | |
const { title: siteTitle, description: siteDescription } = | |
props?.data?.generalSettings; | |
const primaryMenu = props?.data?.headerMenuItems?.nodes ?? []; | |
const footerMenu = props?.data?.footerMenuItems?.nodes ?? []; | |
const { name, posts } = props.data.nodeByUri; | |
return ( | |
<> | |
<SEO title={siteTitle} description={siteDescription} /> | |
<Header | |
title={siteTitle} | |
description={siteDescription} | |
menuItems={primaryMenu} | |
/> | |
<Main> | |
<> | |
<EntryHeader title={`Custom Template: ${name}`} /> | |
<Container> | |
{posts.edges.map((post) => ( | |
<Post | |
title={post.node.title} | |
content={post.node.content} | |
date={post.node.date} | |
author={post.node.author?.node.name} | |
uri={post.node.uri} | |
featuredImage={post.node.featuredImage?.node} | |
/> | |
))} | |
</Container> | |
</> | |
</Main> | |
<Footer title={siteTitle} menuItems={footerMenu} /> | |
</> | |
); | |
} | |
Component.query = gql` | |
${BlogInfoFragment} | |
${NavigationMenu.fragments.entry} | |
${FeaturedImage.fragments.entry} | |
query GetCategoryPage( | |
$uri: String! | |
$headerLocation: MenuLocationEnum | |
$footerLocation: MenuLocationEnum | |
) { | |
nodeByUri(uri: $uri) { | |
... on Category { | |
name | |
posts { | |
edges { | |
node { | |
id | |
title | |
content | |
date | |
uri | |
...FeaturedImageFragment | |
author { | |
node { | |
name | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
generalSettings { | |
...BlogInfoFragment | |
} | |
headerMenuItems: menuItems(where: { location: $headerLocation }) { | |
nodes { | |
...NavigationMenuItemFragment | |
} | |
} | |
footerMenuItems: menuItems(where: { location: $footerLocation }) { | |
nodes { | |
...NavigationMenuItemFragment | |
} | |
} | |
} | |
`; | |
Component.variables = ({ uri }) => { | |
return { | |
uri, | |
headerLocation: MENUS.PRIMARY_LOCATION, | |
footerLocation: MENUS.FOOTER_LOCATION, | |
}; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import category from './category'; | |
import categoryFood from './category-food' | |
import tag from './tag'; | |
import page from './page'; | |
import single from './single'; | |
export default { | |
category, | |
"category-food": categoryFood, | |
tag, | |
page, | |
single, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Both of these files should be created/modified in the
wp-templates
directory. This example would correspond to the category with the slug offood
and would take precedence for that category.