【问题标题】:Wordpress - Elementor custom widgets - conditional controlsWordpress - Elementor 自定义小部件 - 条件控件
【发布时间】:2019-06-01 12:38:45
【问题描述】:

我正在创建我的第一个 elementor 小部件。我需要创建 3 个条件控件: 选择(自定义)post_type -> 选择属于相应 post_type 的分类 -> 选择属于相应分类的帖子。

如何创建这些控件?

这是我到现在为止得到的,但问题是,当我选择一个帖子类型时,在分类列表中我有所有分类,而不仅仅是属于所选 post_type 的那些。

        $post_types = get_post_types([], 'objects');
        $options = [];
        foreach ( $post_types as $post_type ) {
            $options[$post_type->name] = $post_type->label;
        }
        $this->add_control(
            'post_types',
            [
                'label' => __( 'Choose a post type', 'cf-elementor-apm-widget' ),
                'type' => \Elementor\Controls_Manager::SELECT,
                'options' => $options,
                'classes' => 'post_types',
            ]
        );

        $taxonomies = get_taxonomies([], 'objects');

        $options = [];
        foreach ( $taxonomies as $taxonomy ) {
            $options[$taxonomy->name] = $taxonomy->label . " [{$taxonomy->name}]";
        }

        $this->add_control(
            'taxonomies',
            [
                'label' => __( 'Choose a taxonomy', 'cf-elementor-apm-widget' ),
                'type' => \Elementor\Controls_Manager::SELECT,
                'options' => $options,
                'classes' => 'taxonomy',
            ]
        );

【问题讨论】:

  • 你是如何渲染帖子的?

标签: wordpress widget controls elementor


【解决方案1】:

为每种帖子类型创建各种分类选择。如果以编程方式创建它可能会起作用,因此您无需对它们进行硬编码。然后,仅当帖子类型选择的值匹配时才显示特定的分​​类选择。您可以使用control conditions 完成该部分。

【讨论】:

    猜你喜欢
    • 2018-11-23
    • 2022-10-13
    • 2021-11-18
    • 1970-01-01
    • 2020-01-12
    • 2020-08-11
    • 2013-04-06
    • 1970-01-01
    • 2011-12-25
    相关资源
    最近更新 更多