我目前正在开发LayersWP子主题,并注册了一个公文包自定义生成器小部件。
在这个小部件中,我希望用户能够选择他们想要显示的类别。例如:
一个用户有多个公文包项目。一个在类别"艺术"中,一个在"设计"中,还有一个在分类"奉献"中。在主页上,用户只想显示"设计"answers"艺术"类别中的公文包项目。
默认的LayersWP小部件只允许您选择一个特定的类别来显示,不可能选择多个类别。我想把它构建到我的小部件中,但在LayersWP文档中找不到任何关于它的信息。
我有点纠结于如何保存所选的类别。
目前这是我的代码标记:
$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 ?>
那么,我该如何在这个生成器小部件中为用户提供选择多个类别的选项呢。然后保存所选类别?
如有任何帮助,我们将不胜感激。
根据您的需求,您将使用checkboxs
。它已经在层wp post widget
中使用。
参考访问:https://github.com/Obox/layerswp/blob/master/core/widgets/modules/post.php#L524
您也可以在Layerswp支持论坛上联系。你会发现所有对你有帮助的现有问题。
相同参考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/