admin管理员组文章数量:1122832
I am migrating a site from a page builder to a block theme.
In my main post template I want to list other posts in the same category as the current post, excluding the current post itself.
In the page builder, filtering the equivalent blog post list was simple a case of choosing 'current category' from a dropdown, but it's not supported in the default Wordpress Query Loop block.
I was hoping to build a block variation for the Query Loop block but have been unable to work out what I need to do to automatically filter the results in the block based on the current post's category.
wp.blocks.registerBlockVariation(
'core/query',
{
name: 'related-latest-posts',
title: 'Related Latest Posts',
description: 'Displays related posts',
attributes: {
postsToShow: 3
},
query: {
postType: 'post',
postStatus: 'publish',
orderby: 'date',
order: 'desc',
perPage: 3
}
}
);
I am migrating a site from a page builder to a block theme.
In my main post template I want to list other posts in the same category as the current post, excluding the current post itself.
In the page builder, filtering the equivalent blog post list was simple a case of choosing 'current category' from a dropdown, but it's not supported in the default Wordpress Query Loop block.
I was hoping to build a block variation for the Query Loop block but have been unable to work out what I need to do to automatically filter the results in the block based on the current post's category.
wp.blocks.registerBlockVariation(
'core/query',
{
name: 'related-latest-posts',
title: 'Related Latest Posts',
description: 'Displays related posts',
attributes: {
postsToShow: 3
},
query: {
postType: 'post',
postStatus: 'publish',
orderby: 'date',
order: 'desc',
perPage: 3
}
}
);
Share Improve this question edited Apr 16, 2024 at 9:02 J Glasshalfpool asked Apr 16, 2024 at 9:01 J GlasshalfpoolJ Glasshalfpool 112 bronze badges1 Answer
Reset to default 1Curious if you ever figured this one out? I'm running into a similar situation.
本文标签: categoriesHow can I filter Query Loop to show only posts in current category
版权声明:本文标题:categories - How can I filter Query Loop to show only posts in current category? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736286242a1927628.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论