我已经使用选项面板构建了一个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>';
}
}
?>
谢谢。
答案 0 :(得分:1)
之类的东西?
$slider .= '<label>Slide Type</label>';
$slider .= '<div class="slide pixy-checkbox">';
$slider .= '<input class="slide pixy-input pixy-slider-type" name="'. $id .'['.$order.'][type]" type="radio" value="html"';
if($order=='html'){ $slider .= 'checked="checked">'; }else{ $slider .= '>' }
$slider .="<div>HTML Slide</div>";
$slider .= '<input class="slide pixy-input pixy-slider-type" name="'. $id .'['.$order.'][type]" type="radio" value="video"';
if($order=='video'){ $slider .= 'checked="checked">'; }else{ $slider .= '>' }
$slider .= '<div>Video/ Image Wide Slide</div>';
$slider .= '</div>';
这取决于$ order的值,看它是否设置为预设值? 你需要知道这个值才能检查它!
或将其设置为检查选项值(如果已设置1!)?这更容易。
玛蒂