如何使用 WP_Customize_Image_Control 编辑图片滑块?
How can I use WP_Customize_Image_Control to edit an Image Slider?
这是我第一次 post 来到这里,但我一直在做一些搜索。我想使用自定义主题 API 创建添加自定义主题控件以将新图像添加到滑块。这是一些代码:
functions.php
// *** THIS IS THE CUSTOM IMAGE SLIDER SECTION
// Add section for Image Slider Settings
$wp_customize->add_section('image_slider_settings', array(
// Visible title of section
'title' => 'Image Slider Settings',
// Visible Description of what the section is supposed to do
'description' => 'Here you can set up the Image Slider for specific Images,
without code! Select your Image, then add the URL so the new
Image shows on the Image Slider.'
));
// Select an Image
$wp_customize->add_setting('select_image', array(
'default' => null,
'capability' => 'edit_theme_options',
'type' => 'theme_mod',
));
$wp_customize->add_control('select_image_option', array(
'label' => 'Select Image',
'section' => 'image_slider_settings',
'settings' => 'select_image',
'type' => 'checkbox', //********I Don't know what other types there are, but I want to be able to select the image from a dropdown
));
// URL Setting - this is for the Image URL
// so that when the Image is clicked, it routes to the correct page.
$wp_customize->add_setting('image_url', array(
'default' => null,
'capability' => 'edit_theme_options',
'type' => 'theme_mod',
));
$wp_customize->add_control('input_image_url', array(
'label' => 'Image URL',
'section' => 'image_slider_settings',
'settings' => 'image_url',
));
// *** THIS IS THE END OF THE CUSTOM IMAGE SLIDER SECTION
此外,我想我需要拉入滑块中加载的图像数组,以便用户可以 select 来自滑块的图像之一,使用按钮更改图像,并添加将映射到图像的新 URL。这是已经在主题中构建的内容:
homepage.php
<?php
$folder = '/wp-content/uploads/slides/';
$pictures = array(/*array of pictures*/);
$links = array(/*array of links*/);
?>
<a id='slideshow_link' target="_blank">
<?php foreach($pictures as $pic=>$src){
?>
<img id='slideshow_<?php echo $pic ?>' width='976' height='400' style='border:solid 12px #d6d7d4;display:none;' src='<?php echo $src ?>'>
<?php
}
?>
和
var pics_array = new Array (<?php
foreach($pictures as &$pic){
echo " '$pic',";
}
?> null);
var links_array = new Array (<?php
foreach($links as &$l){
echo " '$l',";
}
?> null);
//init slideshow
showPicture(0);
所以最终,我要问的是:
- 我可以使用自定义主题 API 创建图像滑块部分吗?
- 如果是这样,我可以将一组图像及其 URL 路线引入该部分吗?
- 如果是,是否有办法允许用户 select 来自媒体的图像(无论是已经加载到 WordPress 还是就在该部分中)以便用户可以看到新图像滑块外观?
我知道这很多,但我是 WordPress 的新手,我想弄清楚它能做什么,不能做什么。我已经做了很多查找,但似乎无法在其他人提出的问题中找到我要找的东西。
如果有什么我还没有说清楚的,请告诉我。我尽量做到简洁,我相信随着时间的推移我会做得更好,但现在希望这样做。
-斯图
P.S.: 感谢任何能帮助我的人!
所以我想通了。我需要使用 get_theme_mod
将自定义图像滑块挂接到实际图像滑块(用普通 ol' JS 编写)。
关键是要做:
$my_array = array(get_theme_mod(*name_of_setting*), etc);
就是这样。如此简单,但还不是很清楚 get_theme_mod
允许在不涉及任何额外细节的情况下进行挂钩。
这是我第一次 post 来到这里,但我一直在做一些搜索。我想使用自定义主题 API 创建添加自定义主题控件以将新图像添加到滑块。这是一些代码:
functions.php
// *** THIS IS THE CUSTOM IMAGE SLIDER SECTION
// Add section for Image Slider Settings
$wp_customize->add_section('image_slider_settings', array(
// Visible title of section
'title' => 'Image Slider Settings',
// Visible Description of what the section is supposed to do
'description' => 'Here you can set up the Image Slider for specific Images,
without code! Select your Image, then add the URL so the new
Image shows on the Image Slider.'
));
// Select an Image
$wp_customize->add_setting('select_image', array(
'default' => null,
'capability' => 'edit_theme_options',
'type' => 'theme_mod',
));
$wp_customize->add_control('select_image_option', array(
'label' => 'Select Image',
'section' => 'image_slider_settings',
'settings' => 'select_image',
'type' => 'checkbox', //********I Don't know what other types there are, but I want to be able to select the image from a dropdown
));
// URL Setting - this is for the Image URL
// so that when the Image is clicked, it routes to the correct page.
$wp_customize->add_setting('image_url', array(
'default' => null,
'capability' => 'edit_theme_options',
'type' => 'theme_mod',
));
$wp_customize->add_control('input_image_url', array(
'label' => 'Image URL',
'section' => 'image_slider_settings',
'settings' => 'image_url',
));
// *** THIS IS THE END OF THE CUSTOM IMAGE SLIDER SECTION
此外,我想我需要拉入滑块中加载的图像数组,以便用户可以 select 来自滑块的图像之一,使用按钮更改图像,并添加将映射到图像的新 URL。这是已经在主题中构建的内容:
homepage.php
<?php
$folder = '/wp-content/uploads/slides/';
$pictures = array(/*array of pictures*/);
$links = array(/*array of links*/);
?>
<a id='slideshow_link' target="_blank">
<?php foreach($pictures as $pic=>$src){
?>
<img id='slideshow_<?php echo $pic ?>' width='976' height='400' style='border:solid 12px #d6d7d4;display:none;' src='<?php echo $src ?>'>
<?php
}
?>
和
var pics_array = new Array (<?php
foreach($pictures as &$pic){
echo " '$pic',";
}
?> null);
var links_array = new Array (<?php
foreach($links as &$l){
echo " '$l',";
}
?> null);
//init slideshow
showPicture(0);
所以最终,我要问的是:
- 我可以使用自定义主题 API 创建图像滑块部分吗?
- 如果是这样,我可以将一组图像及其 URL 路线引入该部分吗?
- 如果是,是否有办法允许用户 select 来自媒体的图像(无论是已经加载到 WordPress 还是就在该部分中)以便用户可以看到新图像滑块外观?
我知道这很多,但我是 WordPress 的新手,我想弄清楚它能做什么,不能做什么。我已经做了很多查找,但似乎无法在其他人提出的问题中找到我要找的东西。
如果有什么我还没有说清楚的,请告诉我。我尽量做到简洁,我相信随着时间的推移我会做得更好,但现在希望这样做。
-斯图
P.S.: 感谢任何能帮助我的人!
所以我想通了。我需要使用 get_theme_mod
将自定义图像滑块挂接到实际图像滑块(用普通 ol' JS 编写)。
关键是要做:
$my_array = array(get_theme_mod(*name_of_setting*), etc);
就是这样。如此简单,但还不是很清楚 get_theme_mod
允许在不涉及任何额外细节的情况下进行挂钩。