我创建了一个新的自定义帖子类型“Projects”,并希望在mysite上提供所有此类帖子的存档。com/项目。目前,所有项目的单发帖子都显示了一个slug,如下mysite所示。com/projects/project title,但当我访问mysite时。我拿到了404。
下面是我如何构建自定义帖子类型的:
/* Create the Project Custom Post Type ------------------------------------------*/
function create_post_type_project()
{
$labels = array(
\'name\' => __( \'Projects\' ),
\'singular_name\' => __( \'Project\' ),
\'add_new\' => __(\'Add New\'),
\'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 project found\'),
\'not_found_in_trash\' => __(\'No project found in Trash\'),
\'parent_item_colon\' => \'\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'exclude_from_search\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'menu_position\' => null,
// Uncomment the following line to change the slug;
// You must also save your permalink structure to prevent 404 errors
\'rewrite\' => array( \'slug\' => \'projects\' ),
\'has_archive\' => true,
\'supports\' => array(\'title\',\'editor\',\'thumbnail\'),
);
register_post_type(__( \'project\' ),$args);
}