我创建了一个 elementor SELECT2 控件,现在我想显示选定的类别 post 标题和缩略图
I have created an elementor SELECT2 Control and now i want to display selected categories post Title and thumbnail
我已经创建了一个 elementor SELECT2 控件,现在我想显示选定的类别post标题和缩略图
我创建了一个自定义 post 类型,它是 'post_type' => 'video' 在我的控件中显示了所有视频类别,现在我想显示所有选择的 posts Elementor content_template() 和 render() 函数中的标题和缩略图..
<?php
$options = array();
$args = array(
'hide_empty' => false,
'post_type' => 'video',
'taxonomy' => 'video_categories',
);
$categories = get_categories($args);
foreach ( $categories as $key => $category ) {
$options[$category->term_id] = $category->name;
}
$this->add_control(
'video_categories',
[
'label' => __( 'Post Categoris', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::SELECT2,
'multiple' => true,
'options' => $options,
]
);
}
// Want to display selected posts title and thumbnale in loop
protected function render() {
$settings = $this->get_settings_for_display();
foreach ( $settings['show_elements'] as $element ) {
echo '<div>' . $element . '</div>';
}
}
protected function _content_template() {
?>
<# _.each( settings.show_elements, function( element ) { #>
<div>{{{ element }}}</div>
<# } ) #>
<?php
}
}
?> ```
首先你要改变
$settings['show_elements']
到
$settings['video_categories']
$element 仅显示所选类别的 ID。
使用此 WP 函数,您可以在渲染输出中通过 ID 获得类别名称:
get_cat_name( int $cat_id )
要获得所选类别的 post 循环,您必须进一步查看。
我已经创建了一个 elementor SELECT2 控件,现在我想显示选定的类别post标题和缩略图
我创建了一个自定义 post 类型,它是 'post_type' => 'video' 在我的控件中显示了所有视频类别,现在我想显示所有选择的 posts Elementor content_template() 和 render() 函数中的标题和缩略图..
<?php
$options = array();
$args = array(
'hide_empty' => false,
'post_type' => 'video',
'taxonomy' => 'video_categories',
);
$categories = get_categories($args);
foreach ( $categories as $key => $category ) {
$options[$category->term_id] = $category->name;
}
$this->add_control(
'video_categories',
[
'label' => __( 'Post Categoris', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::SELECT2,
'multiple' => true,
'options' => $options,
]
);
}
// Want to display selected posts title and thumbnale in loop
protected function render() {
$settings = $this->get_settings_for_display();
foreach ( $settings['show_elements'] as $element ) {
echo '<div>' . $element . '</div>';
}
}
protected function _content_template() {
?>
<# _.each( settings.show_elements, function( element ) { #>
<div>{{{ element }}}</div>
<# } ) #>
<?php
}
}
?> ```
首先你要改变
$settings['show_elements']
到
$settings['video_categories']
$element 仅显示所选类别的 ID。
使用此 WP 函数,您可以在渲染输出中通过 ID 获得类别名称:
get_cat_name( int $cat_id )
要获得所选类别的 post 循环,您必须进一步查看。