スキン切り換えデモ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_shortcode('skin', function (){ | |
$skin = isset($_GET['theme-switch']) ? esc_html($_GET['theme-switch']) : null; | |
if (empty($skin) && isset($_COOKIE['theme-switch'])) { | |
$skin = esc_html($_COOKIE['theme-switch']); | |
} | |
$url = get_permalink().'?'; | |
ob_start(); | |
?> | |
<select id="theme-switch" class="theme-switch-dropdown" onchange="document.cookie = this.options[this.selectedIndex].value;window.document.location.href='<?php echo $url; ?>'+this.options[this.selectedIndex].value;"> | |
<option value="theme-switch=reset" <?php the_option_selected($skin, null); ?>>▼デザインスキンを選択</option> | |
<option value="theme-switch=cocoon-master" <?php the_option_selected($skin, 'cocoon-master'); ?>>Cocoonデフォルト</option> | |
<option value="theme-switch=skin-simplicity" <?php the_option_selected($skin, 'skin-simplicity'); ?>>Like Simplicity</option> | |
<option value="theme-switch=skin-colors-red" <?php the_option_selected($skin, 'skin-colors-red'); ?>>COLORS(レッド)</option> | |
<option value="theme-switch=skin-colors-blue" <?php the_option_selected($skin, 'skin-colors-blue'); ?>>COLORS(ブルー)</option> | |
<option value="theme-switch=skin-colors-yellow" <?php the_option_selected($skin, 'skin-colors-yellow'); ?>>COLORS(イエロー)</option> | |
<option value="theme-switch=skin-colors-green" <?php the_option_selected($skin, 'skin-colors-green'); ?>>COLORS(グリーン)</option> | |
<option value="theme-switch=skin-colors-pink" <?php the_option_selected($skin, 'skin-colors-pink'); ?>>COLORS(ピンク)</option> | |
</select> | |
<?php | |
return ob_get_clean(); | |
}); | |
function get_skin_url(){ | |
$ts = isset($_COOKIE['theme-switch']) ? esc_html($_COOKIE['theme-switch']) : null; | |
if (isset($_GET['theme-switch'])) { | |
setcookie('theme-switch',esc_html($_GET['theme-switch']),time()+60*60*24*7); | |
} | |
$gts = isset($_GET['theme-switch']) ? esc_html($_GET['theme-switch']) : null; | |
$ts = empty($ts) ? $gts : $ts; | |
switch ($ts) { | |
case 'reset': | |
case 'cocoon-master': | |
setcookie('theme-switch','',time()+60*60*24*7); | |
return; | |
break; | |
default: | |
if ($ts) { | |
return get_template_directory_uri().'/skins/'.$ts.'/style.css'; | |
} else { | |
return get_theme_option(OP_SKIN_URL, ''); | |
} | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment