自定义帖子模板获胜';不起作用


Custom-post template won't work

我已经创建了一个自定义的post类型。我也有singleprojects.php,但由于某些原因,自定义帖子不会使用该模板。我试过冲洗永久链接。我用的是Themefortress幻梦主题。

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();
?>

这是您的错误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);

然后再次刷新永久链接,以便更改生效。

CCD_ 7也就是CCD_。