【发布时间】:2013-06-02 20:18:08
【问题描述】:
WordPress 新手,我一直在尝试为自定义帖子类型创建存档页面,当我单击指向 localhost/websitename/wordpress/archive-event.php 的链接时,我得到一个 404。这是我注册帖子类型的代码:
add_action('init', 'event_register');
function event_register() {
$labels = array(
'name' => _x('Events', 'post type general name'),
'singular_name' => _x('Event', 'post type singular name'),
'add_new' => _x('Add New', 'event'),
'add_new_item' => __('Add New Event'),
'edit_item' => __('Edit Event'),
'new_item' => __('New Event'),
'view_item' => __('View Event'),
'search_items' => __('Search Events'),
'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,
'rewrite' => array('slug' => 'event'),
'has_archive' => 'event',
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','thumbnail'),
);
register_post_type( 'event' , $args );
}
我尝试使用rewrite => true、has_archive => true、刷新重写规则,甚至为帖子类型注册分类。 single-event.php 工作正常。现在呢?
【问题讨论】:
-
您使用任何特定的主题框架吗?一些主题框架稍微改写了通常的层次结构。例如Roots
-
尝试在 wp-admin 面板中再次保存永久链接
-
完成。还是不行。我觉得必须有一些基本的东西我做错了。我是否必须为此创建分类法或类别?我通过保存archive.php 文件创建了一个archive-event.php 页面,并且我没有进行任何更改。我想我认为它的工作方式与 single-event.php 文件相同,这是错误的吗?
标签: php wordpress custom-post-type permalinks