有获得当前块id的方法吗?我想将它添加到在保存函数(registerBlockType)中生成的html中。
我的块的保存部分:
save: props => {
const {
attributes: { images, isCropped },
className,
} = props;
return (
{ images.map( img => (
))}
);
}谢谢!
发布于 2019-02-20 17:06:23
块id保存在clientId字段中。它在每次保存post时重新生成,并且只在编辑函数中的道具中可用。为了将该字段作为保存函数中的唯一id使用,需要将其保存为编辑部分中的属性。然后,它将通过props.attributes在保存函数中可用。
https://wordpress.stackexchange.com/questions/329108
复制相似问题