我已经为滑块创建了一个自定义选项页面,您可以将幻灯片上载到该页面。除了试图保存数据外,一切都很好。它会被保存下来,我可以在前端使用它。但是选项屏幕不会更新,它甚至会在屏幕上执行flickr(我假设它发送表单时会刷新页面)。
我正在使用一个名为Apendo的jQuery插件来克隆幻灯片以添加倍数,我不确定这是否是罪魁祸首。如果手动刷新页面,然后显示正确的内容,这太奇怪了!你知道为什么会这样吗?
这将处理页面的创建和幻灯片的全局设置:
global $slides;
$slides = get_option(\'slides\');
// Add Menu Link
add_action(\'admin_menu\', \'slider_menu_options\');
function slider_menu_options() {
// Check If Form Is Posted & Save An Array
if (isset($_POST[\'action\'])) {
$slides = array();
foreach($_POST[\'src\'] as $k => $v) {
$slides[] = array(
\'src\' => $v,
\'link\' => $_POST[\'link\'][$k],
);
}
update_option(\'slides\', $slides);
}
add_object_page(\'Slider\', \'Slider\', \'edit_themes\', \'slider_settings\', \'slider_options_page\');
}
下面是处理选项的html:
function slider_options_page() {
global $slides;
?>
<div class="wrap" id="manager_wrap">
<h2>Slider Manager</h2>
<form id="manager_form" method="post">
<ul id="manager_form_wrap">
<?php foreach($slides as $k => $slide) : ?>
<li class="slide">
<input type="text" name="link[]" id="slide_link" value="<?php echo $slide[\'link\'] ?>">
<input type="text" name="src[]" class="logo_url" value="<?php echo $slide[\'src\'] ?>"/>
<input class="upload_button" type="button" class="button" value="<?php _e( \'Choose Slide\' ); ?>" />
<div class="upload_preview">
<img style="max-width:100%;" src="<?php echo $slide[\'src\'] ?>" />
</div>
<button class="remove_slide button-secondary">Remove This Slide</button>
</li>
<?php endforeach; ?>
</ul>
<input type="submit" value="Save Changes" id="manager_submit" class="button-primary">
<input type="hidden" name="action" value="save">
</form>
</div>
<?php }
下面是处理一切的jQuery:
jQuery(document).ready(function($) {
$(\'.upload_button\').click(function() {
targetfield = $(this).prev(\'.logo_url\');
imgpreview = $(this).parent().find(\'img\');
tb_show(\'\', \'media-upload.php?type=image&TB_iframe=true\');
window.send_to_editor = function(html) {
imgurl = $(\'img\',html).attr(\'src\');
jQuery(targetfield).val(imgurl);
tb_remove();
$(imgpreview).attr(\'src\', imgurl);
$(\'#submit_options_form\').trigger(\'click\');
};
return false;
});
// calls appendo
$(\'#manager_form_wrap\').appendo({
allowDelete: false,
copyHandlers: true,
focusFirst: false,
labelAdd: \'Add New Slide\',
subSelect: \'li.slide:last\'
});
// slide delete button
$(\'#manager_form_wrap li.slide .remove_slide\').live(\'click\', function() {
if($(\'#manager_form_wrap li.slide\').size() == 1) {
alert(\'Sorry, you need at least one slide\');
}
else {
$(this).parent().slideUp(300, function() {
$(this).remove();
})
}
return false;
});
// jQuery UI sortable
$("#manager_form_wrap").sortable({
placeholder: \'slide-highlight\'
});
});