13

I am using WPML 3.0.2-a with WordPress 3.8.1

I have a custom post type defined like this:

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 );

Visiting a custom post type archive and single post URLs for default language works fine. For example:

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

are working perfectly and displaying what they should.

However, it doesn't work for the other language:

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

are both displaying index.php template of the WordPress theme. It is actualy 404 page but since we don't have 404.php, index.php is used.

Showcases post type is made translatable in WPML settings.

Do you know why is this and how to fix it?

4

4 回答 4

5

我找到了这个支持线程,他们说应该更改以下行(在您的代码中):

'has_archive' => 'case-studies',

至:

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

寻求官方支持可能是个好主意,因为它是商业软件,没有可用的文档。

于 2014-02-11T22:24:08.980 回答
2

我发现了问题所在。

该字符串未在 WPML -> 字符串翻译下翻译

当我翻译它(case-studies -> de/case-studies)时,它起作用了。

实际上,它适用于所有变体 - 我的原始代码和答案中建议的代码。

于 2014-02-19T08:39:09.933 回答
1

我认为这对你有用,只是缺少一些动作:)

'has_archive' => 'case-studies',

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

然后

转到“设置”>“永久链接”并点击“保存”。

让我知道这是否完美。

干杯!

于 2014-02-18T02:42:09.813 回答
0

你有没有尝试过

'has_archive' => true

?

如果我理解正确,应该按需要工作。

于 2014-02-18T15:28:54.053 回答