Skip to content

Instantly share code, notes, and snippets.

@JEverhart383
Created January 24, 2023 13:45
Show Gist options
  • Save JEverhart383/48da4682e6125525570cbaec66c41539 to your computer and use it in GitHub Desktop.
Save JEverhart383/48da4682e6125525570cbaec66c41539 to your computer and use it in GitHub Desktop.
Faust Custom Template Registration
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,
};
};
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,
};
@JEverhart383
Copy link
Author

Both of these files should be created/modified in the wp-templates directory. This example would correspond to the category with the slug of food and would take precedence for that category.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment