2014-02-07 63 views
13

我使用WPML 3.0.2-A與WordPress 3.8.1WPML和自定義文章類型的歸檔模板

我有這樣定義的自定義後類型:

function add_custom_posts(){ 
    $args = array(
      'labels' => array(
        'name' => __('Showcases'), 
        'singular_name' => __('Showcases'), 
        'add_new_item' => __('Add New Showcase'), 
        'edit_item' => __('Edit Showcases'), 
        'view_item' => __('View Showcase'), 
        'search_items' => __('Search Showcases'), 
        'not_found' => __('No Showcases found.'), 
        'not_found_in_trash' => __('No Showcases found in Trash.') 
      ), 
      'public' => true, 
      'has_archive' => 'case-studies', 
      'menu_position' => 5, 
      'taxonomies' => array('post_tag'), 
      'supports' => array('title', 'thumbnail', 'editor', 'excerpt', 'page-attributes'), 
      'rewrite' => array('slug' => 'case-studies', 'with_front' => false), 
      'capability_type' => 'post', 
      'hierarchical' => false, 
     ); 

    register_post_type('showcases', $args); 

} 

add_action('init', 'add_custom_posts', 100); 

訪問自定義類型後存檔和默認語言的單個帖子URL都可以正常工作。例如:

/case-studies/ 
/case-studies/%postname%/ 

正在完美工作,並顯示他們應該。

但是,它並沒有對其他語言的工作:

/de/case-studies/ 
/de/case-studies/%postname%/ 

都顯示的index.php的WordPress主題的模板。這實際上是404頁面,但由於我們沒有404.php,使用了index.php。

展示帖子類型在WPML設置中可翻譯。

你知道這是爲什麼嗎?如何解決它?

回答

2

我發現了什麼問題。

字符串沒有WPML下翻譯 - >字符串翻譯

當我把它翻譯(案例研究 - > DE /案例研究),它的工作。

實際上,它適用於所有變種 - 我的原始代碼和答案中提供的代碼。

5

我發現this support thread,他們說應該更改以下行(在你的代碼):

'has_archive' => 'case-studies', 

到:

'has_archive' => icl_translate('wpml_custom', 'wpml_custom_showcases', 'case-studies'), 

可能是一個好主意,尋求官方支持這是因爲它是商業軟件並且沒有可用的文檔。

+0

不幸的是,它並沒有幫助。 :(你有什麼其他的想法嗎? –

+0

完美地工作!確保你的參數與'register_post_type'中的參數匹配 - 可能爲什麼這對Aleksandar不起作用。它應該是'showcases',而不是'case-studies' –

1

我認爲這會爲你工作,只是缺少一些動作:)

'has_archive' => 'case-studies',

'has_archive' => icl_translate('wpml_custom', 'wpml_custom_showcases', 'case-studies'),

THEN

進入設置>固定鏈接並點擊「保存'。

讓我知道這是否完美。

乾杯!

+0

呵呵,當然我是那麼做的:)但它不起作用。 –

+0

如何看看這個線程:http://wpml.org/forums/topic/translating-slug-for-a-custom-post-type-which-have-a-variable-slug/並使用重寫代替slu for。讓我知道這是否有幫助;) –

0

你試過

'has_archive' => true 

如果我理解正確,應該按需要工作。

+0

不,沒有幫助。必須是別的東西。 –

相關問題