2015-05-28 57 views
0

我註冊了自定義的帖子類型,並將它們放在它自己的子目錄下。這工作正常,但如果我點擊子目錄本身,它會返回一個404.我的問題是如何將子目錄註冊爲模板。我試過爲那個slu creating創建一個頁面模板,但不幸的是,該特定的目錄沒有註冊。下面是我做了什麼:Wordpress CPT子目錄

add_action('init', 'create_post_type'); 
 
function create_post_type() { 
 

 
$postNames = array('NZ-Music', 'Movie-Reviews', 'NZ-Fashion', 'Fashion-Trends', 'Beauty-Tips', 'Beauty-Products', 'Beauty-Trends', 'Gift-Ideas', 'New-Restaurant', 'Restaurant-Review'); 
 

 
foreach ($postNames as $postType) { 
 

 
$lowerCase = strtolower($postType); 
 
$replaceSpace = str_replace("-", " ", $postType); 
 

 
    register_post_type($postType, 
 
    array(
 
     'labels' => array(
 
     'name' => __($replaceSpace), 
 
     'singular_name' => __($postType) 
 
    ), 
 
     'taxonomies' => array('category'), 
 
     'menu_icon' => 'dashicons-' . $lowerCase, 
 
     'rewrite' => $postType . "/" . $postType, 
 
     'public' => true, 
 
     'has_archive' => $postType . "/" . $postType, 
 
    ) 
 
); 
 

 
} 
 

 
} 
 

 

 

對於NZ-音樂的URI會是這個樣子:/ NZ-音樂/後 並且將返回崗位。但是,當我嘗試搜索/ nz-music時,這將返回404.任何想法?

乾杯!

回答