Wordpress自定义帖子类型使用首页

时间:2013-10-28 12:34:15

标签: php wordpress permalinks

编辑请忽略此主题。这个问题完全没有与wordpress或永久链接相关,而是来自一个愚蠢的声音错误。

我已经定义了一个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的页面,该页面支持显示此帖子类型的单个项目。 奇怪的是,事实并非如此。 Probabply与固定链接有关,因为:

  

the_permalink();给出http://kdans.net/e-motion-2012/并导致404错误

     

wp-admin中的固定链接显示http://kdans.net/fotoalbum/e-motion-2012/,其中显示了。{3}}   首页模板(!!)

我确实多次保留固定链接,但是有些问题仍然存在。哪里是我的错?

正如评论中所建议的那样,这里是重写规则。

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)

3 个答案:

答案 0 :(得分:4)

我认为问题在于:'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/

因此,您创建了自定义帖子,当您进行第一次重写时,即从Setting-> Permalinks,它将slug更改为fotoalbum。

尝试将其更改为:'rewrite' => array( 'slug' => 'fotoalbum-item', 'with_front' => true)并重新刷新永久链接。它应该是有效的。

答案 1 :(得分:1)

尝试刷新WP后端中的永久链接结构。保存更改,然后使用您的首选结构再次保存。

答案 2 :(得分:1)

更多关于Wordpress'如何解决问题的见解。给定的固定链接可以提供帮助。也许试试http://wordpress.org/plugins/rewrite-rules-inspector/