编辑 请忽略此主题。问题最终与wordpress或permalinks完全无关,而是来自一个愚蠢的diseding mistrals。
我定义了一个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)
我认为问题就在这里:'rewrite' => array( 'slug' => 'fotoalbum', 'with_front' => true)
因此,当重写发生时,它会从fotoalbum-item更改为fotoalbum。所以这就是为什么网址是 http://kdans.net/fotoalbum/e-motion-2012/而不是 http://kdans.net/fotoalbum-item/e-motion-2012/
因此,您创建自定义帖子,当您从设置>永久链接进行第一次重写时,它将 slug 更改为 fotoalbum。
尝试将其更改为 : 'rewrite' => array( 'slug' => 'fotoalbum-item', 'with_front' => true)
并重新刷新永久链接。它应该是工作。
尝试刷新 WP 后端中的永久链接结构。保存更改,然后使用首选结构再次保存。
关于Wordpress如何"解析"给定的永久链接的更多见解可能会有所帮助。也许试试 http://wordpress.org/plugins/rewrite-rules-inspector/