我创建了一个自定义帖子类型。我也有单个projects.php但由于某种原因自定义帖子不会使用模板。我试图冲洗永久链接。 我正在使用Themefortress Reverie主题。
class projects_post_type {
function projects_post_type() {
add_action('init',array($this,'create_post_type'));
}
function create_post_type() {
$labels = array(
'name' => 'Projects',
'singular_name' => 'Project',
'add_new' => 'Add new',
'all_items' => 'All Projects',
'add_new_item' => 'Add New Project',
'edit_item' => 'Edit Project',
'new_item' => 'New Project',
'view_item' => 'View Project',
'search_items' => 'Search Project',
'not_found' => 'No Projects found',
'not_found_in_trash' => 'No Projects found in trash',
'parent_item_colon' => 'Parent Project:',
'menu_name' => 'Projects'
);
$args = array(
'taxonomies' => array('category','post_tag'),
'labels' => $labels,
'description' => "All Consplan Projects",
'public' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => null,
'capability_type' => 'post',
'hierarchical' => true,
'supports' => array('title','editor','thumbnail','excerpt','custom-fields'),
'has_archive' => true,
'rewrite' => array('slug' => 'projects', 'with_front' => false),
'query_var' => true,
'can_export' => true
);
register_post_type('projects_post_type',$args);
}
}
$projects_post_type = new projects_post_type();
?>
答案 0 :(得分:0)
这是你的错误register_post_type('projects_post_type',$args);
自定义帖子类型的帖子类型为projects_post_type
而不是projects
。
您只需将projects
声明为slug
而不是帖子类型key
替换:
register_post_type('projects_post_type',$args);
有了这个
register_post_type('projects',$args);
然后再次刷新永久链接,以便更改生效。
<single-custom_post_type.php
single-projects.php
现在应该可以使用。