Wagtail Grapple中按分类ID/Slug查询博客的GraphiQL语句求助
通过分类ID或Slug查询指定分类下的博客内容(Wagtail Grapple)
你的BlogPage已经通过@register_paginated_query_field("blogpage")注册了分页查询字段,且在graphql_fields中定义了categories与Category模型的关联,因此可以通过GraphiQL的过滤条件筛选指定分类下的博客内容,以下是两种查询方式:
1. 通过分类ID查询
将your-category-id-here替换为目标分类的实际ID,可按需调整page和perPage分页参数:
query { blogpage( filter: { categories: { id: "your-category-id-here" } } page: 1 perPage: 10 ) { items { id title subtitle introduction datePublished imageUrl categories { id name slug } authors { id name } } pagination { total count perPage currentPage totalPages } } }
2. 通过分类Slug查询
将your-category-slug-here替换为目标分类的实际Slug,分页参数可灵活调整:
query { blogpage( filter: { categories: { slug: "your-category-slug-here" } } page: 1 perPage: 10 ) { items { id title subtitle introduction datePublished imageUrl categories { id name slug } authors { id name } } pagination { total count perPage currentPage totalPages } } }
注意事项
- 确保
base.Category模型已配置对应的GraphQL字段(如id、name、slug),否则无法用于过滤或返回分类信息。 - 若需匹配多个分类,可使用
in操作符,示例:slug: { in: ["tech", "lifestyle"] }
内容的提问来源于stack exchange,提问作者Dhruvin Kalathiya
相关产品推荐
相关产品推荐

