这是我在这里的第一篇帖子,但我一直在做一些搜索。我想使用自定义主题API创建添加自定义主题控件以向滑块添加新图像。以下是一些代码:
功能。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
此外,我想我需要拉入一个加载到滑块中的图像数组,以便用户可以从滑块中选择一个图像,使用按钮更改图像,并添加将映射到图像的新URL。以下是主题中已经构建的内容:
主页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路由拉入该节吗如果是,是否有一种方法允许用户从媒体中选择图像(无论是已加载到WordPress还是就在该部分中),以便用户可以看到新的图像滑块外观我知道这有很多,但我对WordPress还不熟悉,我正在努力弄清楚它能做什么和不能做什么。我做了很多寻找,只是在别人提出的问题中似乎找不到我想要的东西。
如果有什么我还没有弄清楚的地方,请告诉我。我尽可能地简洁,我相信我会随着时间的推移做得更好,但现在希望这样就可以了。
-斯图。
P、 谢谢所有能帮助我的人!