如何为定制帖子创建单一模板

时间:2018-03-06 作者:Dinesh

我创建一个自定义帖子类型,在主题中添加以下代码functions.php

function  cptarchivePost_init() {
    $args = array(
      \'label\' => \'Archive Post\',
        \'public\' => true,
        \'show_ui\' => true,
        \'capability_type\' => \'post\',
        \'hierarchical\' => false,
        \'rewrite\' => array(\'slug\' => \'cpt_archive_post\'),
        \'query_var\' => true,
        \'menu_icon\' => \'dashicons-video-alt\',
        \'supports\' => array(
            \'title\',
            \'editor\',
            \'excerpt\',
            \'trackbacks\',
            \'custom-fields\',
            \'comments\',
            \'revisions\',
            \'thumbnail\',
            \'author\',
            \'page-attributes\',)
        );
    register_post_type( \'cpt_archive_post\', $args );
}
add_action( \'init\', \'cptarchivePost_init\' );

add_action( \'init\', \'create_cpt_archive_category\', 0 );
function create_cpt_archive_category() {
    register_taxonomy(
        \'cpt_archive_category\',
        \'cpt_archive_post\',
        array(
            \'labels\' => array(
                \'name\' => \'Category\',
                \'add_new_item\' => \'Add Category\',
                \'new_item_name\' => "New Category"
            ),
            \'show_ui\' => true,
            \'show_tagcloud\' => false,
            \'hierarchical\' => true
        )
    );
}
并在主题中创建一个名为single-cpt_archive_post.php 但仍然是使用索引的帖子。php模板

有人能帮助我如何为自定义帖子创建单个模板吗

1 个回复
SO网友:Beee

您还可以将(页面)模板用于自定义帖子类型,请参见this link.

只需将此添加到模板文件:

Template Post Type: your-post-type

结束

相关推荐