admin管理员组文章数量:1421176
I have created a block that wraps the <img>
in a <div>
so that I can style a scrollable image.
It all seems to be working. When I save the caption it appears to be saved on the Frontend and Backend.
However, it doesn't seem to actually update the image->caption in the database. When looking at the media library and selecting the image, the image caption is not updated.
Here's the code for the backend.
edit(props) {
const { className, setAttributes } = props;
const { attributes } = props;
// function that will take the changes from RichText
// and update the attributes (state)
function changeCaption(imgCaption) {
setAttributes({ imgCaption: imgCaption });
}
function selectImage(value) {
// console.log(value);
setAttributes({
imgUrl: value.sizes.full.url,
})
setAttributes({
imgCaption: value.caption,
})
}
return [
<InspectorControls>
<div style={{padding: '1em 0',}}>
Options
</div>
</InspectorControls>,
<div className={className}>
<figure className="media">
<div className="mediaScroll">
<MediaUpload
onSelect={selectImage}
render={ ({open}) => {
return (
<button onClick={open}>
<img
src={attributes.imgUrl}
/>
</button>
);
}}
/>
</div>
<RichText
className="testing-caption"
tagName="figcaption"
placeholder="Enter an image caption"
value={attributes.imgCaption}
onChange={changeCaption}
/>
</figure>
</div>,
];
},
So how would I go about trying to achieve this? As I understand images are saved in the db under wp_posts -> post_excerpt.
post_excerpt is the caption.
Is there an API for updating the database from the edit() ?
本文标签: Custom Image Gutenberg Block With Caption
版权声明:本文标题:Custom Image Gutenberg Block With Caption 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745349190a2654658.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论