我已经建立了一个带有选项面板的 WP 主题,但我有一个小问题。
如果您正在查看下面的代码,我有两个复选框(type="radio")问题是这些复选框在我刷新选项页面后没有保留它们的选项,但是它们被添加到数据库中,因为我看到了更改在前端。
public static function optionsframework_slider_function($id,$std,$oldorder,$order,$int){
$data = get_option(OPTIONS);
$slider = '';
$slide = array();
$slide = $data[$id];
if (isset($slide[$oldorder])) { $val = $slide[$oldorder]; } else {$val = $std;}
//initialize all vars
$slidevars = array('type', 'title', 'desc', 'content');
foreach ($slidevars as $slidevar) {
if (!isset($val[$slidevar])) {
$val[$slidevar] = '';
}
}
//begin slider interface
if (!empty($val['title'])) {
$slider .= '<li><div class="slide_header"><strong>'.stripslashes($val['title']).'</strong>';
} else {
$slider .= '<li><div class="slide_header"><strong>Slide '.$order.'</strong>';
}
$slider .= '<input type="hidden" class="slide pixy-input order" name="'. $id .'['.$order.'][order]" id="'. $id.'_'.$order .'_slide_order" value="'.$order.'" />';
$slider .= '<a class="slide_edit_button" href="#">Edit</a></div>';
$slider .= '<div class="slide_body">';
$slider .= '<label>Slide Type</label>';
$slider .= '
<div class="slide pixy-checkbox">
<input class="slide pixy-input pixy-slider-type" name="'. $id .'['.$order.'][type]" type="radio" value="html"><div>HTML Slide</div>
<input class="slide pixy-input pixy-slider-type" name="'. $id .'['.$order.'][type]" type="radio" value="video"><div>Video/ Image Wide Slide</div>
</div>
';
$slider .= '<label>Slide Title</label>';
$slider .= '<input class="slide pixy-input pixy-slider-title" name="'. $id .'['.$order.'][title]" id="'. $id .'_'.$order .'_slide_title" value="'. stripslashes($val['title']) .'" />';
$slider .= '<label>Slide Description</label>';
$slider .= '<input class="slide pixy-input" name="'. $id .'['.$order.'][desc]" id="'. $id .'_'.$order .'_slide_desc" value="'. $val['desc'] .'" />';
$slider .= '<label>Slide Content</label>';
$slider .= '<textarea class="slide pixy-input" name="'. $id .'['.$order.'][content]" id="'. $id .'_'.$order .'_slide_content" cols="8" rows="8">'.stripslashes($val['content']).'</textarea>';
$slider .= '<a class="slide_delete_button" href="#">Delete</a>';
$slider .= '<div class="clear"></div>' . "\n";
$slider .= '</div>';
$slider .= '</li>';
return $slider;
}
复选框的代码是(*可以在上面的代码中找到):
$slider .= '<label>Slide Type</label>';
$slider .= '
<div class="slide pixy-checkbox">
<input class="slide pixy-input pixy-slider-type" name="'. $id .'['.$order.'][type]" type="radio" value="html"><div>HTML Slide</div>
<input class="slide pixy-input pixy-slider-type" name="'. $id .'['.$order.'][type]" type="radio" value="video"><div>Video/ Image Wide Slide</div>
</div>
';
这是在前端打印滑块的代码:
<?php
$slides = $data['pixy_pixyGallery_slider'];
if($slides) {
foreach ($slides as $slide) {
echo '<li data-type="'.$slide['type'].'" data-title="'.$slide['title'].'" data-caption="'.$slide['desc'].'">';
echo do_shortcode( $slide['content'] );
echo '</li>';
}
}
?>
谢谢你。