我已经将我的主题设置为激活页面上创建和设置模板的位置,如何添加古腾堡块?
UPDATE:
不创建页面,如果我注释掉page\\u block\\u模板函数并将“post\\u content”设为空字符串\' \'
然后它将创建页面。那么如何做到这一点,向页面模板添加块呢?
函数向页面添加块。
function page_block_template() {
$pages_type_object = get_post_type_object( \'page\' );
$pages_type_object->template = array(
array( \'core/heading\', array(
\'level\' => \'3\',
\'className\' => \'header\',
\'content\' => \'\'
) ),
array( \'core/separator\', array(
\'className\' => \'is-style-wide\'
) ),
array( \'core/paragraph\', array(
\'className\' => \'margin\',
) ),
array( \'core/list\', array(
\'className\' => \'list-unstyled h5\',
// STYLE <li class="list-inline-item"> ??
) ),
array( \'core/heading\', array(
\'level\' => \'3\',
\'className\' => \'header\',
\'content\' => \'\'
) ),
array( \'core/separator\', array(
\'className\' => \'is-style-wide\'
) ),
);
$pages_type_object->template_lock = \'all\';
}
add_action( \'init\', \'page_block_template\' );
创建页面
if (isset($_GET[\'activated\']) && is_admin()) {
$page_title = \'Page\';
$page_content = page_block_template();
$page_check = get_page_by_title($page_title);
$page = array(
\'post_type\' => \'page\',
\'post_title\' => $page_title,
\'post_content\' => $page_content,
\'post_status\' => \'publish\',
\'post_author\' => $user_id,
\'post_slug\' => \'page\'
);
if(!isset($page_check->ID) && !the_slug_exists(\'page\')) {
$page_id = wp_insert_post($page);
}
}