我想为elementor创建自定义小部件。在这个小工具中,用户可以创建一个图像滑块,并在每个图像上创建一些标记。所以我为图像创建了一个repeater控件,为标记创建了另一个。在标记重复器中,我添加了一个选择器,用户可以选择图像并将标记添加到选定的图像。
图像中继器输出:
Array
(
[0] => Array
(
[image_title] => Image 1
[_id] => fe58385
[image_url] => Array
(
[url] => ../wp-content/uploads/2023/05/big-pic-1.png
[id] => 1326
[size] =>
[alt] =>
[source] => library
)
)
[1] => Array
(
[image_title] => Image 2
[_id] => 40a0cc6
[image_url] => Array
(
[url] => ../wp-content/uploads/2023/05/big-pic-2.png
[id] => 1327
[size] =>
[alt] =>
[source] => library
)
)
)
和标记输出:
Array
(
[0] => Array
(
[marker_title] => mark1-1
[marker_top] => 40
[marker_left] => 100
[_id] => 6763ae7
[marker_parent] => 0
[marker_desc] => Lorem ipsum dolor sit amet, ne est populo dictas, et pri ferri ubique labitur.
Mel ad euismod adipiscing moderatius eos an decore quodsi animal.
)
[1] => Array
(
[marker_title] => mark2-1
[marker_top] => 60
[marker_left] => 100
[marker_parent] => 0
[marker_desc] => Lorem ipsum dolor sit amet, ne est populo dictas, et pri ferri ubique labitur.
Mel ad euismod adipiscing moderatius eos an decore quodsi animal.
[_id] => 9d1b611
)
[2] => Array
(
[marker_title] => mark1-2
[marker_top] => 40
[marker_left] => 100
[marker_parent] => 1
[marker_desc] => Lorem ipsum dolor sit amet, ne est populo dictas, et pri ferri ubique labitur.
Mel ad euismod adipiscing moderatius eos an decore quodsi animal.
[_id] => 6030c28
)
)
在标记中,您可以看到用户选择图像的[marker_parent]值(用于检查图像索引)。我想添加标记到图像数组作为新的值,如['标记']属于正确的图像。
怎么解决呢?
我写了这个循环来做到这一点:
$settings = $this->get_settings_for_display();
$images = $settings['images'];
$markers = $settings['markers'];
foreach ($images as $key=>$image) :
if($key == $markers['marker_parent']){
$image['marker'] = $markers[$key];
}
endforeach;
1条答案
按热度按时间w1jd8yoj1#
我想我明白你想要什么了,这段代码将基于
marker_parent
字段作为images数组的索引,将markers
数组Map到images
数组。产量: