简体   繁体   English

从定制帖子类型中选择多个类别以显示在LayersWP构建器小部件中

[英]Selecting multiple categories from a custom post type to be displayed in LayersWP builder widget

I am currently developing a LayersWP child theme and have registered a portfolio custom builder widget. 我目前正在开发LayersWP子主题,并注册了产品组合自定义构建器小部件。

In this widget i would like users to be able to select the categories that they want shown. 在此小部件中,我希望用户能够选择他们想要显示的类别。 For example: 例如:

“A user has multiple portfolio items. “用户有多个投资组合项目。 One in the category”Art”, one in the category “Design” and one in the category “Devolpment”. 一种是“艺术”类别,一种是“设计”类别,一种是“发展”类别。 On the homepage the user only wants to show portfolio items in the category “Design” and “Art”. 在主页上,用户只希望在“设计”和“艺术”类别中显示投资组合项目。

The default LayersWP widget only lets u choose one specific category to show, it's not possible to select multiple categories. 默认的LayersWP小部件仅允许您选择一个要显示的特定类别,而不能选择多个类别。 I would like to build this into my widget but can't really find anything about it in the LayersWP docs. 我想将其构建到我的窗口小部件中,但实际上在LayersWP文档中找不到任何有关它的信息。

I am kind of struggling on how to save the categories that are selected. 我在如何保存选定的类别方面有些挣扎。

Currently this is my code markup: 当前,这是我的代码标记:

 $terms = get_terms( $this->taxonomy );
                    if( !is_wp_error( $terms ) ) { ?>
                        <p class="layers-form-item">
                            <label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php echo __( 'Category to Display' , LAYERS_THEME_SLUG ); ?></label>
                            <?php $category_options[ 0 ] ="All";
                            foreach ( $terms as $t ) $category_options[ $t->term_id ] = $t->name;
                            echo $this->form_elements()->input(
                                array(
                                    'type' => 'select',
                                    'name' => $this->get_field_name( 'category' ) ,
                                    'id' => $this->get_field_id( 'category' ) ,
                                    'placeholder' => __( 'Select a Category' , LAYERS_THEME_SLUG ),
                                    'value' => ( isset( $categories ) ) ? $categories : NULL ,
                                    'options' => $category_options
                                ) 
                            ); ?>
                        </p>
                    <?php } // if !is_wp_error ?>

So how exactly do i give users the option to select multiple categories in this builder widget. 因此,我如何为用户提供在该构建器小部件中选择多个类别的选项。 And then save the categories that are selected? 然后保存选择的类别?

Any help is appreciated 任何帮助表示赞赏

As per your requirement, You'll use checkboxs . 根据您的要求,您将使用checkboxs It was already used in layerswp post widget . 它已经在layerswp post widget

For reference visit: https://github.com/Obox/layerswp/blob/master/core/widgets/modules/post.php#L524 供参考,请访问: https://github.com/Obox/layerswp/blob/master/core/widgets/modules/post.php#L524 : https://github.com/Obox/layerswp/blob/master/core/widgets/modules/post.php#L524

You'll also contact on Layerswp support forum. 您还将在Layerswp支持论坛上联系。 You'll found all existing question which helps you. 您会发现所有现有的问题都可以帮助您。

Same reference http://docs.layerswp.com/forums/question/how-to-set-a-new-field-type-of-multi-select-in-to-grab-the-category-value-in-layers-builder-widgets/ 相同的参考http://docs.layerswp.com/forums/question/how-to-set-a-new-field-type-of-multi-select-in-to-grab-the-category-value-in-layers-builder-widgets/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM