如何防止自定义帖子类型使用Archive.php模板?

时间:2013-05-08 作者:janoChen

我有以下几点:

//Jobs
register_post_type( \'jobs\',
    array(
        \'labels\' => array(
            \'name\' => __( \'Jobs\' ),
            \'singular_name\' => __( \'Job\' )
        ),
    \'public\' => true,
        \'show_ui\' => true,
    \'has_archive\' => false,
        \'hierarchical\' => true,
        \'query_var\' => true,
        \'supports\' => array( \'title\', \'editor\', \'comments\', \'trackbacks\', \'revisions\',\'author\', \'excerpt\', \'custom-fields\', \'thumbnail\', \'page-attribute\' ),
    \'rewrite\' => array(\'slug\' => \'jobs\', \'with_front\' => true),
        \'taxonomies\' => array( \'post_tag\', \'category\'),
        \'can_export\' => true,
    \'show_in_nav_menus\' => true,
    //\'capability_type\'=>\'jobs\',
    //\'capabilities\' => array(
    //  \'read_post\' => \'read_jobs\'
    //),
    )
);
我试过这个:\'has_archive\' => false,

但作业自定义帖子类型仍在使用archive.php 样板

你知道这里出了什么问题吗?

1 个回复
最合适的回答,由SO网友:Grant Palin 整理而成

如果要为自定义类型使用专门的存档模板,则需要额外的存档文件。其命名形式为:

archive-[custom post type name].php

因为您的代码列表jobs 作为类型名称,存档文件将命名为:

archive-jobs.php

这可以类似于标准存档模板,也可以根据自定义内容类型的性质进行定制。

结束

相关推荐

显示Archives.php中的所有自定义帖子类型

我该怎么做?archive.php 只有以下内容:wp_get_archives(\'type=monthly\'); 以及wp_get_archives() 没有显示所有帖子类型的参数。我也认为archive-[post_type].php 不是我要找的,因为我希望所有帖子类型都显示在一个归档页面中。谢谢W