个性化阅读
专注于IT技术分析

使用Polylang的自定义帖子类型多语言

点击下载

我有一个我现在不解决的问题。多亏了Polylang插件, 我们有了一个多语言的wordpress页面。除了来自其他插件的自定义帖子类型外, 其他所有内容都可以正常运行。使用此自定义帖子类型创建的帖子会加载基本语言(英语)的内容, 但是只要我们更改语言, 它就会停止工作。它不加载内容

我注册了这样的帖子类型:

register_post_type( 'placement', array(
        'labels' => array(
            'name' => __( 'Placementy' ), 'singular_name' => __( 'Placement' )
        ), 'public' => true, 'menu_icon' => 'dashicons-welcome-write-blog'
    )
);

我试过了, 在我的functions.php中注册帖子类型, 而不是在插件主文件中注册, 仍然相同…其他自定义帖子类型运行良好, 并且注册方式相同。我也尝试在我的wordpress主题中为自定义帖子类型创建模板, 而不是使用插件中的模板, 但是它也失败了……不知道为什么它不起作用。尤其是当其他一切正常时。更改后还清除了缓存。已检查开发人员和本地环境中的更改。什么会导致这种行为?


#1


在functions.php中

    add_filter('pll_get_post_types', 'add_cpt_to_pll', 10, 2);
function add_cpt_to_pll($post_types, $hide) {
    if ($hide)
        // hides 'my_cpt' from the list of custom post types in Polylang settings
        unset($post_types['my_cpt']);
    else
        // enables language and translation management for 'my_cpt'
        $post_types['my_cpt'] = 'my_cpt';
    return $post_types;
}

有关更多详细信息, 请参见https://polylang.wordpress.com/documentation/documentation-for-developers/filter-reference/

赞(0)
未经允许不得转载:srcmini » 使用Polylang的自定义帖子类型多语言

评论 抢沙发

评论前必须登录!