自定义帖子类型功能类型‘页面’不起作用

时间:2014-03-07 作者:scferg5

我正在尝试创建一个自定义帖子类型,该类型应该用于出版物问题->文章结构。因为层次结构是really only meant for pages (参见hierarchical 节的注释),我想我应该配置自定义帖子类型作为页面。

太好了,只是我不能让它正常工作。即使在设置之后capability_typepagehierarchicaltrue, 帖子类型的编辑屏幕仍像帖子一样工作。没有任何“父”或“页面模板”属性下拉菜单。

如果我更改capability_type 从…起pagepost, 实际上,编辑屏幕没有任何变化。

这是我的代码:

register_post_type(\'publication\', array(
    \'label\' => \'Publication\',
    \'public\' => true,
    \'show_ui\' => true,
    \'show_in_menu\' => true,
    \'capability_type\' => \'page\',
    \'map_meta_cap\' => true,
    \'hierarchical\' => true,
    \'rewrite\' => array(\'slug\' => \'publication\', \'with_front\' => true),
    \'query_var\' => true,
    \'supports\' => array(\'title\',\'editor\',\'comments\',\'revisions\',\'author\',\'page-attributes\'),
    \'labels\' => array (
        \'name\' => \'Publications\',
        \'singular_name\' => \'Publication\',
        \'menu_name\' => \'Publications\',
    )
));
你知道这里怎么了吗?

2 个回复
SO网友:Nathan Fitzgerald - Fitzgenius

我从我制作的另一个使用层次结构的网站上获取了这一信息,它很有效。(我已修改以适合您的职位类型)

function register_publications_cpt() {

        $labels = array(
            \'name\' => _x(\'Publications\', \'post type general name\'),
            \'singular_name\' => _x(\'Publication\', \'post type singular name\'),
            \'add_new\' => _x(\'Add New\', \'\'),
            \'add_new_item\' => __(\'Add New Publication\'),
            \'edit_item\' => __(\'Edit Publication\'),
            \'new_item\' => __(\'New Publication\'),
            \'all_items\' => __(\'All Publication\'),
            \'view_item\' => __(\'View Publication\'),
            \'search_items\' => __(\'Search Publications\'),
            \'not_found\' =>  __(\'No Publications found\'),
            \'not_found_in_trash\' => __(\'No Publications found in Trash\'), 
            \'parent_item_colon\' => \'\',
            \'menu_name\' => \'Publications\'
        );

        $args = array(
            \'hierarchical\' => true,     
            \'labels\' => $labels,
            \'public\' => true,
            \'publicly_queryable\' => true,
            \'show_ui\' => true, 
            \'show_in_menu\' => true, 
            \'query_var\' => true,
            \'rewrite\' => true,
            \'capability_type\' => \'page\',
            \'has_archive\' => false, 
            \'menu_position\' => 22,
            \'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'revisions\', \'page-attributes\', \'custom-fields\' )
        ); 

        register_post_type(\'publication\', $args);

}
add_action(\'init\', \'register_publications_cpt\');

SO网友:arroni

老问题,但我自己在寻找答案。。。

创建帖子类型时,您需要两件事来解决此问题:

\'hierarchical\' => true,
\'supports\' => array(\'page-attributes\'),
这将为您提供一个模板选择和一个订单菜单。

结束

相关推荐