图库块重构 Gutenberg Wordpress

发布于 2025-01-13 18:37:16 字数 409 浏览 1 评论 0原文

根据下面的开发说明:

https: //make.wordpress.org/core/2021/08/20/gallery-block-refactor-dev-note/

古腾堡画廊块的 HTML 结构已从 UL 更改> LI至图>数字。没关系,但现在,我们不像以前那样在每个画廊项目上都有 CSS 类,我知道通过 CSS 选择该画廊上的子元素不是问题,但问题是当我们必须使用块钩子 render_block 通过 PHP 对块结构进行一些更改,我通过使用其类名称来选择图库项目,但现在这是不可能的。这里有人面临同样的问题吗?

according to the dev note bellow:

https://make.wordpress.org/core/2021/08/20/gallery-block-refactor-dev-note/

the HTML structure of the Gutenberg gallery block has been changed from a UL > LI to FIGURE > FIGURE. That is okay, but now, we don't have a CSS class on each gallery item as we had before, I know that via CSS this is not a problem to select child elements on this gallery, but the problem is when we have to make some changes into the block structure via PHP using the block hook render_block, I was selecting gallery items by using its classes names, and now, this is not possible. Is anyone here facing this same problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喜爱皱眉﹌ 2025-01-20 18:37:16

Gallery 块中的每个图像都可以在 Advanced > 下分配自己的自定义 CSS 类。其他 CSS 类。然后,自定义名称存储在块属性中,在执行自定义解析/渲染块时可以通过 PHP 访问这些属性。

图库块

类名应用于 HTML,因为

<figure class="wp-block-gallery">
    <figure class="wp-block-image size-large my-custom-class">
        <img/>
    </figure>
    <figure class="wp-block-image size-large">
        <img/>
    </figure>
</figure>

我假设在 PHP 中您正在使用 parse_blocks() 或您自己的自定义函数来呈现内容。

Each Image within a Gallery block can have its own custom CSS class assigned under Advanced > Additional CSS class(es). The custom names are then stored in the block attributes, which are accessible via PHP when doing custom parsing/rendering the block.

Gallery Block

The class name is applied to the HTML as

<figure class="wp-block-gallery">
    <figure class="wp-block-image size-large my-custom-class">
        <img/>
    </figure>
    <figure class="wp-block-image size-large">
        <img/>
    </figure>
</figure>

I assume in PHP you are using parse_blocks() or your own custom function to render the content.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文