我想创建一个自定义的帖子类型,如帖子或页面,它应该有页面模板选项。这是针对多语言网站的。对此有何评论?
如何创建自定义帖子类型,如佩奇
你应该看看register_post_type
抄本中的页码。看看hierarchical
注册帖子类型时的参数
hierarchical (布尔)(可选)
帖子类型是否为层次结构(如页面)。允许指定父级。“supports”参数应包含“page attributes”,以在编辑器页面上显示父选择框。
默认值:false
否,默认情况下,您不能将模板支持添加到自定义帖子类型。但也有一些插件支持此功能。
您可以使用Custom Post Template 或Single Post Template Plugin 插件添加了对单个帖子的模板支持,其中也包括自定义帖子类型。
你可以在这里了解更多。Can I assign a template to a custom post type?
已经讨论过了。在本主题中,还有其他一些方法,但不适用于单个帖子。尽管您可以为帖子类型设置模板。
自定义帖子类型模板
存档-{post\\u type}。phpsingle-{post\\u type}。php
archive-{post_type}.php 如果您的自定义帖子类型为“product”和/或query\\u var=“product”,WordPress将查找归档产品。php来显示帖子的存档。
single-{post_type}.php 如果您的自定义帖子类型为“product”和/或query\\u var=“product”,WordPress将查找单个产品。php显示文章的单个或永久链接。
如果这些文件在主题目录中不可用,WordPress将查找存档文件。php和single。php。如果这些文件都不存在,它将默认为索引。php。有关详细信息,请参见模板层次结构。
创建自定义帖子类型创建帖子类型页面
$page = get_page_by_path(\'buyer-order-request\');
if (!$page) {
$buyer_order_requ= \'[buyer_order_request]\';
$post = array(
\'comment_status\' => \'closed\',
\'ping_status\' => \'closed\' ,
\'post_author\' => 1,
\'post_content\' => $buyer_order_requ,
\'post_date\' => date(\'Y-m-d H:i:s\'),
\'post_name\' => \'buyer-order-request\',
\'post_status\' => \'publish\' ,
\'post_title\' => \'Buyer Order Request\',
\'post_type\' => \'page\',
);
//insert page and save the id
$newvalue = wp_insert_post( $post, false );
//save the id in the database
update_option( \'buyerorder_page\', $newvalue );
}