我已經用選項面板構建了一個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>';
}
}
?>
謝謝。
你爲什麼不考你的選項,並打印的價值'檢查=「是」'如果有必要嗎? –