自定义帖子类型模板在预览和发布之间更改

时间:2012-05-25 作者:BrettAdamsGA

我已经设置了一个标题为project 我还设置了一个主题文件page-project.php. 当我在该自定义帖子类型下创建帖子并预览它时,它会显示在page-project.php 但是,一旦我发布它并查看页面,它就会使用index.php 样板有人能告诉我为什么会这样吗?

这是我的自定义帖子类型functions.php

仅供参考:刚刚发现,如果我将永久链接设置为默认设置,它也会使用正确的模板。

add_action(\'init\', \'project_register\'); 
function project_register() {
    $labels = array(
        \'name\' => _x(\'My Projects\', \'post type general name\'),
        \'singular_name\' => _x(\'Project\', \'post type singular name\'),
        \'add_new\' => _x(\'Add New\', \'project item\'),
        \'add_new_item\' => __(\'Add New Project Item\'),
        \'edit_item\' => __(\'Edit Project Item\'),
        \'new_item\' => __(\'New Project Item\'),
        \'view_item\' => __(\'View Project Item\'),
        \'search_items\' => __(\'Search Project\'),
        \'not_found\' =>  __(\'Nothing found\'),
        \'not_found_in_trash\' => __(\'Nothing found in Trash\'),
        \'parent_item_colon\' => \'\'
    );
    $args = array(
        \'labels\' => $labels,
        \'public\' => true,
        \'publicly_queryable\' => true,
        \'show_ui\' => true,
        \'query_var\' => true,
        \'menu_icon\' => get_stylesheet_directory_uri() . \'/article16.png\',
        \'rewrite\' => true,
        \'capability_type\' => \'page\',
        \'hierarchical\' => false,
        \'menu_position\' => null,
        \'supports\' => array(\'title\',\'editor\',\'thumbnail\',\'author\')
      );

    $labels = array(
    \'name\' => _x( \'Project Types\', \'taxonomy general name\' ),
    \'singular_name\' => _x( \'Project Type\', \'taxonomy singular name\' ),
    \'search_items\' =>  __( \'Search Project Types\' ),
    \'all_items\' => __( \'All Project Types\' ),
    \'parent_item\' => __( \'Parent Project Type\' ),
    \'parent_item_colon\' => __( \'Parent Project Type:\' ),
    \'edit_item\' => __( \'Edit Project Type\' ), 
    \'update_item\' => __( \'Update Project Type\' ),
    \'add_new_item\' => __( \'Add New Project Type\' ),
    \'new_item_name\' => __( \'New Project Type Name\' ),
    \'menu_name\' => __( \'Project Type\' ),
  ); 
    register_taxonomy(\'project_type\',array(\'project\'), array(\'hierarchical\' => true,
    \'labels\' => $labels,
    \'show_ui\' => true,
    \'query_var\' => true,
    \'rewrite\' => array( \'slug\' => \'type\' ),));
    register_post_type( \'project\' , $args );
}

1 个回复
SO网友:Chip Bennett

自定义帖子不使用custom static page template files. 自定义帖子有自己的模板文件custom post archive index pagessingle custom post pages.

对于单个自定义贴子页面,您需要创建single-{post-type}.php, 对你来说single-project.php.

类似地,对于自定义存档后索引页,您需要创建archive-{post-type}.php, 对你来说archive-project.php.

结束

相关推荐