在WordPress主题选项中使用单选按钮

时间:2011-02-19 20:01:38

标签: wordpress themes

我完全陷入困境。

我一直致力于提供5种不同布局和3种不同皮肤的主题。在主题选项中,我最初使用复选框来选择皮肤和布局,但是被要求(由ThemeForest)将它们更改为单选按钮。起初,我想,没问题。现在我很无能为力。

在标题中,layout + skin选项的示例如下所示:

<!-- Content Alt (Layout 2)-->
<?php if (( $mp_content_alt == 'true' ) && ( $mp_skin1 == 'true') ){ ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/_styles/skins/l2_coolblue.css" type="text/css" media="screen,projection" />

<?php } elseif (( $mp_content_alt == 'true' ) && ( $mp_skin2 == 'true') ){ ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/_styles/skins/l2_justminimal.css" type="text/css" media="screen,projection" />

<?php } elseif (( $mp_content_alt == 'true' ) && ( $mp_skin3 == 'true') ){ ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/_styles/l2.css"  type="text/css" media="screen,projection" />

<?php } ?>

在functions.php中我设置了这样的无线电选项:

$shortname = "mp";
$layout = array("1" => "Original", "2" => "Original + Left Sidebar", "3" => "Wider  Images + Right Sidebar", "4" => "Large Images + No Text", "5" => "Smaller Images Gallery");
$skins = array("1" => "Original", "2" => "Cool Blue", "3" => "Just Minimal");

array( "name" => "Choose A Skin",
"desc" => "",
"id" => $shortname."_skins",
"type" => "radio",
"options" => $skins,
"std" => ""),

array( "name" => "Layout Options",
    "desc" => "Choose Your Layout",
    "id" => $shortname."_layouts",
    "type" => "radio",
    "options" => $layout,
    "std" => ""),

我很难理解如何拨打不同的无线电选项?我试过这个:

<!-- Content (Layout 1)-->
<?php if ((checked( isset( $mp_layouts['1'] ) ) ) && (checked( isset( $mp_skins['2'] ) ) ) ){ ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/_styles/skins/l1_coolblue.css" type="text/css" media="screen,projection" />

<?php } elseif ((checked( isset( $mp_layouts['1'] ) ) ) && (checked( isset(   $mp_skins['3'] ) ) ) ){ ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/_styles/skins /l1_justminimal.css" type="text/css" media="screen,projection" />

<?php } elseif ( (checked( isset( $mp_layouts['1'] ) ) ) && (checked( isset( $mp_skins['1'] ) ) ) ){ ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/style.css" type="text/css" media="screen,projection" />

<?php } ?>

但那没用。

有什么建议吗?

非常感谢!

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。

首先,我必须在变量中定义选项:

<?php if ( ( $layout = get_option('of_layout') ) && ( $skin = get_option('of_skin') ) ) { ?>

然后我引用数组中的选项:

<!-- Content (Layout 1)-->
<?php if (( $layout == 'Layout1' ) && ( $skin == ( 'Original' ) ) ){ ?>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css"  media="screen,projection" />

<?php } elseif (( $layout == 'Layout1' ) && ( $skin == ( 'Blue' ) ) ){ ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/_styles/skins/l1_coolblue.css" type="text/css" media="screen,projection" />

<?php } elseif (( $layout == 'Layout1' ) && ( $skin == ( 'Minimal' ) ) ){ ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/_styles/skins/l1_justminimal.css" type="text/css" media="screen,projection" />

<?php } ?>

不同布局的数组包含:Layout1,Layout2等。 不同外观的数组包含:原始,蓝色,最小等