我想我们可以将模板应用于custom page types:
不能以这种方式将模板应用于自定义帖子类型。仅当帖子类型为“页面”时才会显示
我的代码:
function keyword_pages_init() {
$args = array(
\'label\' => \'Keywords\',
\'public\' => true,
\'show_ui\' => true,
\'capability_type\' => \'page\',
\'hierarchical\' => false,
\'rewrite\' => array(\'slug\' => \'keywords\'),
\'query_var\' => true,
\'menu_icon\' => \'dashicons-admin-page\',
\'supports\' => array(
\'title\',
\'editor\',
\'excerpt\',
\'trackbacks\',
\'custom-fields\',
\'comments\',
\'revisions\',
\'thumbnail\',
\'author\',
\'page-attributes\',
)
);
register_post_type( \'keywords\', $args );
}
add_action( \'init\', \'keyword_pages_init\' );
但是
template
未显示在下
page attributes
当我尝试在这个自定义页面类型下添加新页面时。
有什么想法吗?
最合适的回答,由SO网友:Joe Dooley 整理而成
你指的是新的Post Type Templates feature included in 4.7?
制作page template 对于“关键字”cpt可用,您需要将这样的标题添加到自定义页面模板中。
/**
* Template Name: Template Name
* Template Post Type: post, page, keywords
*/
此模板将可用于所有帖子、页面和您的关键字cpt。下面是一个完整页面模板的示例。。。
<?php
/**
* ACF Flexible Content template
*
* Learn more: https://codex.wordpress.org/Template_Hierarchy
*
* @package YM
* @since 1.0
* @version 1.0
*/
/**
* Template Name: Flexible Content
* Template Post Type: post, page, product, event
*/
/**
* Add landing page body class to the head
*
* @param $classes
* @return array
*/
add_filter( \'body_class\', function ( $classes ) {
$classes[] = \'flexible-content-template\';
return $classes;
} );
/**
* Remove entry header
*/
remove_action( \'genesis_entry_header\', \'genesis_do_post_title\' );
/**
* Force full width layout
*/
add_filter( \'genesis_pre_get_option_site_layout\', \'__genesis_return_full_width_content\' );
/**
* Remove breadcrumbs
*/
remove_action( \'genesis_before_loop\', \'genesis_do_breadcrumbs\' );
/**
* Add ACF Flexible Content. See inc/layout.php
*
* @uses ym_flexible_content();
*/
remove_action( \'genesis_loop\', \'genesis_do_loop\' );
add_action( \'genesis_after_header\', \'ym_flexible_content\' );
genesis();
https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/