Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit ca0060c

Browse files
committed
Merge branch 'feature/33-category-archive' into develop
2 parents 48c21b0 + a91b5b0 commit ca0060c

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

api/wordpress/_global/getPostTypeStaticProps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ export default async function getPostTypeStaticProps(
8181
Object.keys(archiveQuerySeo).includes(postType) &&
8282
params.slug.length > 1
8383
) {
84-
const taxonomy = params.slug.shift()
85-
const taxonomySlug = params.slug.join('/')
84+
const taxonomy = params.slug.shift() // First "slug" piece is taxonomy type.
85+
const taxonomySlug = params.slug.pop() // Last "slug" piece is the lowest-level taxonomy term slug.
8686

8787
const {apolloClient, ...archiveData} = await getPostTypeTaxonomyArchive(
8888
taxonomy,

api/wordpress/_global/getPostTypeTaxonomyArchive.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {postTypes} from './postTypes'
33
import formatDefaultSeoData from '@/functions/formatDefaultSeoData'
44
import getMenus from '../menus/getMenus'
55
import queryPostsByTag from '../tags/queryPostsByTag'
6+
import queryPostsByCategory from '../categories/queryPostsByCategory'
67

78
/**
89
* Retrieve post taxnomy archive.
@@ -30,6 +31,7 @@ export default async function getPostTypeTaxonomyArchive(
3031
) {
3132
// Define single post query based on taxonomy.
3233
const postTypeQuery = {
34+
category: queryPostsByCategory,
3335
tag: queryPostsByTag
3436
}
3537

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {gql} from '@apollo/client'
2+
import defaultPageData from '../_partials/defaultPageData'
3+
import {archivePostFragment, archivePosts} from '../posts/queryPostsArchive'
4+
import seoPostFields from '../_partials/seoPostFields'
5+
6+
// Query: retrieve posts category archive.
7+
const queryPostsByCategory = gql`
8+
query GET_POSTS_BY_CATEGORY(
9+
$first: Int
10+
$last: Int
11+
$after: String
12+
$before: String
13+
$orderBy: PostObjectsConnectionOrderbyEnum = DATE
14+
$order: OrderEnum = DESC
15+
$imageSize: MediaItemSizeEnum = THUMBNAIL
16+
$id: ID!
17+
$idType: CategoryIdType = SLUG
18+
) {
19+
${defaultPageData}
20+
category(id: $id, idType: $idType) {
21+
${seoPostFields}
22+
${archivePosts}
23+
}
24+
}
25+
${archivePostFragment}
26+
`
27+
28+
export default queryPostsByCategory

0 commit comments

Comments
 (0)