网格+;Wordpress源插件-如何按月份和年份添加存档路由
我必须在基于Gridsome(Wordpress作为数据源)的博客中添加一个归档小部件。像这样的标准功能: 我使用静态查询获取帖子:网格+;Wordpress源插件-如何按月份和年份添加存档路由,wordpress,vue.js,graphql,vue-router,gridsome,Wordpress,Vue.js,Graphql,Vue Router,Gridsome,我必须在基于Gridsome(Wordpress作为数据源)的博客中添加一个归档小部件。像这样的标准功能: 我使用静态查询获取帖子: query Home($page: Int) { allWordPressPost(page: $page) { pageInfo { totalPages currentPage } edges { node { date(format: "YYYY-MM-DD")
query Home($page: Int) {
allWordPressPost(page: $page) {
pageInfo {
totalPages
currentPage
}
edges {
node {
date(format: "YYYY-MM-DD")
id
title
path
}
}
}
}
接下来,在monthed hook上,我按年份和月份将数据分组到这样的输出中:
{
"2019": {
"10": [
{
"date": "2019-10-29",
"node": {
"date": "2019-10-29",
"id": "145",
"title": "Aspernatur ipsam est omnis praesentium rerum autem",
"path": "/2019/10/29/aspernatur-ipsam-est-omnis-praesentium-rerum-autem/"
}
},
{
"date": "2019-10-29",
"node": {
"date": "2019-10-29",
"id": "121",
"title": "Libero voluptatibus facere aspernatur",
"path": "/2019/10/29/libero-voluptatibus-facere-aspernatur/"
}
}
],
"09": [
{
"date": "2019-09-25",
"node": {
"date": "2019-09-25",
"id": "1",
"title": "Hello world!",
"path": "/2019/09/25/hello-world/"
}
}
]
}
}
我使用结构化和标准v-for循环语法生成了小部件链接,但示例路由(如:“”、“”)转到404页面。我试图通过添加以下内容来修改gridsome.config.js:
templates: {
WordPressArchive: [
{
path: "/blog/:year",
component: "./src/templates/WordPressArchive.vue"
}
]
},
它会导致错误:
"Error: A content type for the WordPressArchive template does not exist"
我如何在Gridsome中启用归档路由以按年份和年/月过滤博客帖子
"/blog/:year",
"/blog/:year/:month"
是否可以直接从graphQL查询中按日期和年份对帖子进行分组,而无需进一步的js操作?您的graphQL中有一个
WordPressPost
类型,并且您正在尝试使用WordPressArchive
作为模板名称。这些需要匹配,或者在GraphQL中更改typeName
,或者在gridsome.config.js
中更改模板名称