WordPress Gutenberg 核心/查询块在自定义变体中缺少网格视图选项

问题描述 投票:0回答:1

我遇到了古腾堡中核心/查询块的自定义块变体的问题。具体来说,我在自定义块变体中缺少网格视图选项。

这是我的变体注册代码:

const VARIATION_NAME = 'custom_variation_query_loop';

registerBlockVariation('core/query', {
    name: custom_variation_query_loop,
    title: 'Custom Variation Query Loop',
    description: 'Variation (Custom)',
    usesContext: ["query", "displayLayout"],
    isActive: ( blockAttributes ) =>
        blockAttributes.namespace === VARIATION_NAME,
    icon: 'admin-links',
    attributes: {
        namespace: VARIATION_NAME,
        displayLayout: {
            type: 'flex',
            columns: 2,
        },
        query: {
            postType: 'destination',
            orderBy: 'title',
            perPage: 12,
            offset: 0,
        },
    },
    innerBlocks: [
        [
            'hwrdp/post-template-id-filter',
            {},
            [
                ['core/post-title', { level: 0, isLink: true, fontSize: 'large' }],
            ],
        ],
        ['core/query-no-results'],
    ],
    scope: [ 'block', 'inserter' ],
});

自定义变体中的其他所有内容均按预期工作。但是,网格视图选项不可用。

有人遇到过类似的问题吗?有关可能导致此问题的原因以及如何修复它的任何指示吗?

  1. 使用 registerBlockVariation 为核心/查询注册了自定义块变体。
  2. 提供了必要的属性,包括具有弹性布局和2列的displayLayout。
  3. 检查并确保主题、WordPress 和所有相关插件均已更新。
  4. 验证了PHP端,确保没有干扰,看起来与问题无关
javascript php wordpress wordpress-gutenberg
1个回答
0
投票

我测试了您的变体代码,当您选择自定义变体查询循环的帖子模板时,网格选项会按预期显示:

我会尝试使用默认的帖子模板来排除自定义

[hwrdp/post-template-id-filter]
块的任何潜在问题,例如:

innerBlocks: [
        [
            'core/post-template',
            {
                'layout': {
                    type: 'grid',
                    columnCount: 2
                }
            },
           [['core/post-title', { level: 0, isLink: true, fontSize: 'large' }]],
        ],
        ['core/query-no-results'],
    ],
...

除此之外,我能看到的唯一问题是

name
的值可能存在拼写错误,我希望它是:

registerBlockVariation('core/query', {
    name: VARIATION_NAME,
...
});
© www.soinside.com 2019 - 2024. All rights reserved.