Temam için bir Tema Seçenekleri sayfası hazırlıyorum ve çoğunun iyi çalışmasını sağladım. Ama şimdi temamdaki bazı kısımları basit bir onay kutusuna dayanarak gösterip gizlemeye çalışıyorum. Bir örnek:
Öne çıkan içerik kaydırıcısını göster? - Evet Hayır
Kullanıcı evet'i seçtiğinde, aşağıdaki kodu temamın belirli bir şablonunda etkinleştirmek istiyorum:
<?php locate_template( array( 'includes/slider.php'), true ) ?>
Peki bu kodu yalnızca Evet tıklandığında görünecek şekilde nasıl sarabilirim? Bence bu bir tür şartlı ifade ama şimdi buna nasıl yaklaşılacağı hakkında fikrim var. PHP yazamadığım için bu konuda biraz yardıma ihtiyacım var :) Bu seçeneğin adı bpslick_featured olarak adlandırılır.
Şimdiden teşekkürler!
@ Bowe
Onay kutusundaki seçenekler işlevinizde bir dizi oluşturmanız ve kimliğe varsayılan durum vermeniz ve "onay kutusu" türünü atamanız gerekir. Yönetici paneli için kodun zaten bulunduğunu varsayan bir örnek
<?php
// Set variables for the options panel
$themename = "your_theme_name";
$themeshortname = "yt";
$mythemeoptions = array();
//The Option function
function cool_theme_options() {
global $themename, $themeshortname, $mythemeoptions;
$themeoptions = array (
array( "name" => __('Show featured content slider','your_theme_name'),
"desc" => __('When checked, the slider will be added to the home page.','your_theme_name'),
"id" => "show_featured_slider",
"std" => "false",
"type" => "checkbox"
),
);
}
//The Option Form
function my_cool_theme_admin() {
global $themename, $themeshortname, $themeoptions;
// Saved or Updated message
if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
// The form
?>
<div class="wrap">
<h2><?php echo $themename; ?> Options</h2>
<form method="post">
<?php wp_nonce_field('theme-save'); ?>
<table class="form-table">
<?php foreach ($themeoptions as $value) {
// Output the appropriate form element
switch ( $value['type'] ) {
case 'text':
?>
<tr valign="top">
<th scope="row"><?php echo $value['name']; ?>:</th>
<td>
<?php foreach ($value['options'] as $key=>$option) {
if ($key == get_option($value['id'], $value['std']) ) {
$checked = "checked=\"checked\"";
} else {
$checked = "";
}
?>
<input type="radio" name="<?php echo $value['id']; ?>" value="<?php echo $key; ?>" <?php echo $checked; ?> /><?php echo $option; ?><br />
<?php } ?>
<?php echo $value['desc']; ?>
</td>
</tr>
<?php
break;
case "checkbox":
?>
<tr valign="top">
<th scope="row"><?php echo $value['name']; ?></th>
<td>
<?php
if(get_option($value['id'])){
$checked = "checked=\"checked\"";
} else {
$checked = "";
}
?>
<input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
<?php echo $value['desc']; ?>
</td>
</tr>
<?php
break;
default:
break;
}
}
?>
</table>
<p class="submit">
<input name="save" type="submit" value="Save changes" class="button-primary" />
<input type="hidden" name="action" value="save" />
</p>
</form>
<form method="post">
<?php wp_nonce_field('theme-reset'); ?>
<p class="submit">
<input name="reset" type="submit" value="Reset" />
<input type="hidden" name="action" value="reset" />
</p>
</form>
Ardından, kutu işaretliyse, kaydırıcıyı çağıran işlev.php işlevine ekleyin.
<?php
function cool_theme_slider_option() {
// load the custom options
global $themeoptions;
foreach ($themeoptions as $value) {
$$value['id'] = get_option($value['id'], $value['std']);
}
if ($show_featured_slider == 'true') {
locate_template( array( 'includes/slider.php'), true )
}
} // end function
add_action('wp_head', 'cool_theme_slider_option');
?>
Bu kod tam olarak çalıştığından emin olmak için kontrol edilmedi ancak temanızda bir onay kutusu seçeneği kullanmak için bir örnek göstermesi gerekiyordu.