编辑请忽略这个话题。这个问题最终与 wordpress 或永久链接无关,而是来自一个愚蠢的 voeding misrals。
我已经定义了一个 wordpress 自定义帖子类型,如下所示:
add_action('init', 'fotoalbums_register_posttype');
function fotoalbums_register_posttype() {
register_post_type( 'fotoalbum-item' , array(
'labels' => array(
'name' => 'Fotoalbums',
'singular_name' => 'Fotoalbum',
'menu_name' => 'Fotoalbums',
'all_items' => 'Overzicht',
'add_new' => 'Nieuw album',
'add_new_item' => 'Nieuw album',
'edit_item' => 'Bewerk album',
'new_item' => 'Nieuw album',
'view_item' => 'Bekijk album',
'search_items' => 'Zoek albums',
'not_found' => 'Niet gevonden',
),
'public' => true,
'has_archive' => false,
'show_ui' => true,
'capability_type' => 'page',
'hierarchical' => false,
'supports' => array('title', 'editor') ,
'menu_position' => 31,
'rewrite' => array( 'slug' => 'fotoalbum', 'with_front' => true)
)//end array
); //end register_post_type()
}//end function fotoalbums_register_posttype()
然后我创建了一个名为 single-fotoalbum-item.php 的页面,支持显示此帖子类型的单个项目。奇怪的是,它没有。可能与永久链接有关,因为:
the_permalink(); 给出http://kdans.net/e-motion-2012/并导致 404 错误
wp-admin 中的永久链接显示http://kdans.net/fotoalbum/e-motion-2012/,它显示了首页模板(!!)
我确实多次保留了永久链接,但是这个问题不断出现的一些人。我的错在哪里?
正如评论中所建议的,这里是重写规则。
http://kdans.net/fotoalbum/e-motion-2012/ gives:
index.php?fotoalbum-item=$matches[1]&page=$matches[2] (source fotoalbum-item)
index.php?pagename=$matches[1]&page=$matches[2] (source: page)
index.php?attachment=$matches[1] (source: post)
http://kdans.net/e-motion-2012/ gives
index.php?pagename=$matches[1]&page=$matches[2] (source: page)
index.php?name=$matches[1]&page=$matches[2] (source: post)