wordpress - 标题未显示在前端 - 古腾堡
问题描述
我有这个组件'PostTitle',它获取页面标题并在您编辑在编辑器中工作的主页标题时发生变化,但我无法让它显示在前端?不知道我做错了什么。
更新
我添加了一个函数来更新“标题”属性,但问题是它只在编辑时触发。因此,如果您不在编辑器中单击组件,它将不会更新“标题”属性。有没有办法把这个放到存档区?
registerBlockType( 'gutenberg/title', {
title: 'updating text',
icon: 'universal-access-alt',
category: 'layout',
attributes: {
title: {
type: 'array',
source: 'children',
selector: 'h1',
},
},
edit( { attributes } ) {
const { title } = attributes;
const GetTitle = props => props.title;
//I'm not sure how to get this to update the title attribute
const selectTitle = withSelect(select => ({
title: select("core/editor").getDocumentTitle(),
}));
const PostTitle = selectTitle(GetTitle);
//update function that fire when you edit the component
function updateTitle() {
const pagetitle = select("core/editor").getDocumentTitle();
setAttributes( { title: pagetitle } );
console.log(pagetitle);
}
updateTitle();
const controls = (
<Fragment>
.....
</Fragment>
);
return (
<Fragment>
{ controls }
<PostTitle/>
</Fragment>
);
},
save( { attributes } ) {
const { title } = attributes;
return (
<div>
<RichText.Content tagName="h1" className="title" value={ title } />
</div>
);
},
} );
任何帮助将非常感激
解决方案
推荐阅读
- javascript - 选择必要的选项时如何过滤?
- python - (1,)在python中是什么意思
- python - Python 等价于 java junit assertequals
- synchronization - 如何以编程方式将启用 scim 的应用程序实例化到 Azure
- graphviz - Graphviz:xlabel 和 nodelabel 的不同颜色
- django - ValueError:即使在 collectstatic 之后也缺少静态文件清单条目
- vim - viminfo 中的标记格式
- python - numpy: sqrt in place: 这是一个错误吗?
- python - 如何为脚本计时数千次
- python - 我必须编辑 QColorDialog 小部件内部组件的样式表