admin管理员组文章数量:1320661
What I am trying to do is to use specific Reusable Blocks, that are editable by certain admins in the back end, within block templates for custom post types. So if you register a CTP or edit the capabilities of standard post types, you can use them like:
function create_add_post_types() {
register_post_type( 'product',
array(
'public' => true,
'capability_type' => 'page',
'show_in_rest' => true,
'template' => array(
array( 'core/heading', array(
'placeholder' => 'Füge eine Überschrift hinzu',
'content' => 'Projektname - Stadt, Land',
'level' => 1,
) ),
)
);
}
add_action( 'init', 'create_add_post_types' );
..except that insteadt of a core block like the heading here a reusable block is called.
What I am trying to do is to use specific Reusable Blocks, that are editable by certain admins in the back end, within block templates for custom post types. So if you register a CTP or edit the capabilities of standard post types, you can use them like:
function create_add_post_types() {
register_post_type( 'product',
array(
'public' => true,
'capability_type' => 'page',
'show_in_rest' => true,
'template' => array(
array( 'core/heading', array(
'placeholder' => 'Füge eine Überschrift hinzu',
'content' => 'Projektname - Stadt, Land',
'level' => 1,
) ),
)
);
}
add_action( 'init', 'create_add_post_types' );
..except that insteadt of a core block like the heading here a reusable block is called.
Share Improve this question edited Feb 7, 2019 at 13:52 Playnary asked Feb 7, 2019 at 13:06 PlaynaryPlaynary 3253 silver badges12 bronze badges2 Answers
Reset to default 4I actually found a solution myself by following the way a reusable block is registered in this stackexchange thread:
Reusable blocks are all stored in/as core/block and this block has the attribute ref which carries the post id of that block.
So, you can use
array( 'core/block', array(
'ref' => [your block ID],
) ),
and the ID of every registered block is visible via the URL of that block at [your-wordpress]/wp-admin/edit.php?post_type=wp_block
You can call a reusable block as you call to any post type:
$args = array(
'post_type' => 'wp_block',
...
OR
get_page_by_title( 'Your Title', OBJECT, 'wp_block' );
本文标签: themesIs it possible to access Gutenbergs reusable blocks in CPT block templates
版权声明:本文标题:themes - Is it possible to access Gutenbergs reusable blocks in CPT block templates? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742065849a2418829.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论