admin管理员组文章数量:1125102
I'm writing a plugin that provides a custom post type. I am currently trying to create the block templates for the "single" and the "archive" associated with the custom post type via single-slug.html
and archive-slug.html
files in the plugin. I do not seem to be succeeding.
This method does not seem to work for me so far:
add_filter(
'get_block_templates',
function ( $query_result, $query ) {
if ( isset( $query['theme'] ) && isset( $query['slug__in'] ) && isset( $query['slug__in'][1] ) ) {
foreach ( $query['slug__in'] as $slug ) {
$template_file_path = plugin_dir_path( __FILE__ ) . '/includes/templates/' . $slug . '.html';
if ( file_exists( $template_file_path ) ) {
$html = file_get_contents( $template_file_path );
array_push(
$query_result,
(object) array(
'title' => sprintf( __( 'Default %s', 'post-type-slug' ), $slug ),
'slug' => $slug,
'status' => 'publish',
'type' => 'wp_template',
'description' => sprintf( __( 'Default %s template', 'post-type-slug' ), $slug ),
'content' => $html,
'source' => 'plugin',
'is_custom' => false,
'is_customized' => false,
'is_reusable' => false,
'is_reserved' => false,
'is_published' => true,
'is_wp_template_part' => false,
)
);
}
}
}
return $query_result;
},
10,
2
);
And I am a little stuck on how to continue. Any guidance would be appreciated.
本文标签: Add block templates (html) via plugin for custom post type
版权声明:本文标题:Add block templates (html) via plugin for custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736652190a1946165.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论