2016-09-23 34 views
0

我有aj-fashions自定義帖子類型。從技術上說,我試圖在名爲fashio-template.php的模板文件中顯示所有帖子的循環,現在爲單個帖子創建了文件single-fashions.php。仍然我正在404頁面找不到錯誤。自定義帖子類型單頁不起作用

請注意,以下是我的代碼。

add_action('init', 'fashion'); 
function fashion() { 
    register_post_type('aj-fashion', 
    array(
     'labels' => array(
     'name' => __('AJ Fasions'), 
     'singular_name' => __('AJ Fashion') 
    ), 
     'public' => true, 
     'has_archive' => true, 
     'show_ui' => true, 
     'hierarchical' => false, 
     'rewrite' => array('slug' => 'aj-fashions',), 
     'supports'=> array('title', 'editor', 'thumbnail', 'author'), 
    ) 
); 
} 
+0

adding flush_rewrite_rules();工作。 –

+0

什麼是單個帖子特定的帖子循環? –

+0

從設置更新固定鏈接。 –

回答

1

使用single-{posttype}.php作爲單個模板。另外,如果您註冊了您的帖子類型並將has_archive參數設置爲true,那麼您可以使用archive-{posttype}.php作爲您的存檔模板,這將允許您跳過那裏的查詢,因爲全局$wp_query對象已經填充了您的自定義帖子類型。

在示例

single-fashions.php而不是single-aj-fashion.php下方的情況下檢查。

+0

我的自定義帖子類型=「aj-fasion」,這就是爲什麼我把它命名爲單aj-fashion.php?我做錯了嗎?親切的建議 –

+0

你沒有錯,但它是一個wordpress標準,無論你用在'register_post_type'中的slug是否需要在單個ex之後添加slug:'single- {posttypeslug} .php'。它對你有用嗎? – purvik7373

+0

是的,slu is也叫「aj-fashion」:) –

相關問題