I am using Kirki Option framework which works like charm in most cases, I recently shifted from Redux framework. I have a section in my website for the gallery, I want to upload multiple images using Kirki 'image' control where I want to save those images ID. I have custom image size for the thumbnail which is defined in functions.php file:
我正在使用Kirki选项框架,在大多数情况下,它的工作方式类似于Charge,我最近从Redux框架转向了它。我在我的网站上有一个图库的部分,我想上传多个图像使用Kirki‘IMAGE’控制在哪里我想保存这些图像ID。我有自定义的缩略图图像大小,这是定义在unctions.php文件:
add_image_size('home-gallery-thumb', 400, 300, true);
and this is what I am using to create a field in customizer:
这是我用来在Customizer中创建一个字段的内容:
Kirki::add_field( 'my_gallery', [
'type' => 'image',
'settings' => 'my_gallery_st',
'label' => esc_html__( 'Gallery Images', 'txtdom' ),
'description' => esc_html__( 'Upload Images for the gallery section', 'txtdom' ),
'section' => 'my_gallery_sc',
'choices' => [
'save_as' => 'id',
],
]
);
In the output I want to display thumbnail using wp_get_attachment_image_src()
function for the specific image ID and when user clicks the image the full image will display in lightbox.
在输出中,我希望为特定的图像ID使用wp_GET_ATTACH_IMAGE_src()函数显示缩略图,当用户单击图像时,完整的图像将显示在lightbox中。
But the problem is using this control I can only upload one image. I don't know what I am missing out. I did research in google for the issue and found that the multiple image upload feature is implemented from Kirki 3.1 version but I don't find anything to use it in their documentation. Can anyone help me do this?
但问题是,使用这个控件,我只能上传一张图片。我不知道我错过了什么。我就这个问题在谷歌上做了研究,发现多张图片上传功能是从Kirki 3.1版本开始实现的,但我在他们的文档中找不到任何可以使用它的东西。有人能帮我做这件事吗?
Thanks in advance.
先谢谢你。
更多回答
var image = wp.media( { multiple: false } ).open().on( 'select', function() {
- In the Kirki Image field code, multiple
is set to false. So I dont think that Image
field will accept multiple images.
Var image=wp.media({Multiple:False}).Open().on(‘SELECT’,Function(){-在Kirki Image字段代码中,Multiple设置为False。因此,我认为Image字段不会接受多个图像。
I used to do it by Redux Gallery field but don't know how can I do similar in Kirki. Is there any way?
我曾经在Redux Gallery field这样做,但不知道如何在Kirki做类似的事情。有什么办法吗?
优秀答案推荐
Try following code use it as a controller:
尝试以下代码,将其用作控制器:
Kirki::add_field( 'my_gallery', [
'type' => 'repeater',
'settings' => 'my_gallery_images',
'label' => esc_html__( 'Gallery Images', 'txtdom' ),
'section' => 'my_gallery_sc',
'row_label' => [
'type' => 'text',
'value' => esc_html__( 'Image', 'txtdom' ),
],
'button_label' => esc_html__( 'Add New Image', 'txtdom' ),
'fields' => [
'image' => [
'type' => 'image',
'label' => esc_html__( 'Image', 'txtdom' ),
'description' => esc_html__( 'Upload an image for the gallery section', 'txtdom' ),
'choices' => [
'save_as' => 'id',
],
],
],
] );
then use that controller by following code:
然后通过以下代码使用该控制器:
$gallery_images = get_theme_mod( 'my_gallery_images', [] );
foreach ( $gallery_images as $image ) {
$image_id = $image['image'];
$image_url = wp_get_attachment_image_src( $image_id, 'home-gallery-thumb' );
if ( $image_url ) {
echo '<a href="' . esc_url( wp_get_attachment_image_url( $image_id, 'full' ) ) . '" data-lightbox="gallery">';
echo '<img src="' . esc_url( $image_url[0] ) . '" alt="" />';
echo '</a>';
}
}
You can create a gallery of multiple images, With that code.
您可以使用该代码创建多个图片库。
更多回答
This works but using this, user have to upload each image separately by creating new row in repeater. I want to upload multiple images as gallery. For example I want to use similar to Redux Gallery field.
这是可行的,但使用这种方法,用户必须通过在中继器中创建新行来分别上传每个图像。我想上传多幅图片作为画廊。例如,我想使用类似于Redux图库的字段。
I don't have any idea. sorry.
我一点也不知道。抱歉的。
我是一名优秀的程序员,十分优秀!