Custom post types templates

时间:2012-07-09 作者:Anurag Ahuja

我已经注册了一个名为“Services”的自定义帖子类型,但当我给这篇帖子提供模板“single Services.php”时,它不接受这个,而是选择了“homepage.php”模板,你能告诉我这个问题吗?它也没有使用“archive services.php”模板,而是使用blog模板(index.php)

使现代化代码如下:

add_action(\'init\', \'services_register\');
function services_register() {

$labels = array(
    \'name\' => _x(\'Services\', \'post type general name\'),
    \'singular_name\' => _x(\'Service\', \'post type singular name\'),
    \'add_new\' => _x(\'Add New\', \'service\'),
    \'add_new_item\' => __(\'Add New Service\'),
    \'edit_item\' => __(\'Edit Service\'),
    \'new_item\' => __(\'New Service\'),
    \'view_item\' => __(\'View Service\'),
    \'search_items\' => __(\'Search Service\'),
    \'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\' => null,
    \'rewrite\' => true,
    \'capability_type\' => \'post\',
    \'hierarchical\' => false,
    \'menu_position\' => null,
    \'supports\' => array(\'title\',\'editor\',\'thumbnail\')
  ); 

register_post_type( \'services\' , $args );
}

1 个回复
SO网友:Rabin shrestha

如果您只是注册一个名为“服务”的自定义帖子类型,那么您的注册代码应该看起来像register\\u post\\u type(\'services\',$args);确保“services”一词在register\\u post\\u type中准确无误。并且您的post\\u type单词最多应包含20个字符,不能包含大写字母或空格

还要确保has\\u archive参数设置为true,例如“has\\u archive”=>true,

不要忘记在slug或permalink中进行任何更改后,通过在后端的permalink设置中单击save来刷新重写规则。希望这对你有帮助

结束

相关推荐