这是我在这里的第一篇文章,但我一直在做一些搜索。我想使用自定义主题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
此外,我想我需要拉入滑块中加载的图像数组,以便用户可以从滑块中选择一个图像,使用按钮更改图像,然后添加将映射到Image的新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);
所以最终,我要问的是:
我知道这很多,但我是WordPress的新手,我试图弄清楚它能做什么,不能做什么。我做了很多寻找,似乎无法在其他人提出的问题中找到我想要的东西。
请告诉我是否有任何我可以清理的事情,我已经明确表示不清楚了。我试着尽可能地简洁,我确信随着时间的推移,我会做得更好,但是现在希望这样做。
-Stu。
P.S。:感谢任何可以帮助我的人!
答案 0 :(得分:0)
所以我想出来了。我需要使用get_theme_mod
将自定义图像滑块挂钩到实际的图像滑块(用简单的'JS'编写)。
关键只是:
$my_array = array(get_theme_mod(*name_of_setting*), etc);
就是这样。如此简单,但get_theme_mod
允许挂钩而不涉及任何额外细节并不是很清楚。