0
所以我试图建立一个条件语句显示不同的布局,取决于选择的选项。wp_customize和选择布局
有点麻烦。
$wp_customize->add_setting('layout', array(
'default' => 'stream',
)); // add our default setting.
$wp_customize->add_control('layout', array(
'label' => __('Select layout', 'Ari'),
'section' => 'layout',
'settings' => 'layout',
'type' => 'radio',
'choices' => array(
'stream' => 'Stream',
'grid' => 'Grid',
),
)); // use radio buttons with (so far) two choices.
$wp_customize->add_section('layout' , array(
'title' => __('Layout','Ari'),
)); // add our layout section in the customize panel.
显示我们的布局。
<?php if (get_theme_mod('stream')) : ?>
<p>stream</p> if (have_posts()) etc
<?php elseif (get_theme_mod('grid')) : ?>
<p>grid</p> // if (have_posts()) etc
<?php else : //Nothing ?>
<?php endif; ?>
只是......没有。我浏览了Codex,看不到我做错了什么。它只是不显示任何输出。
@Stewartside指出,我应该使用get_setting,但我无法得到这个工作。任何人?
我已经挖了一通,我不知道该怎么做。我是否以正确的方式(理论上)?即。从选定的主题设置输出不同的PHP/HTML? – andy
理论上是的,这是if语句的正确方法。唯一的问题是get_theme_mod在真正需要true或false时检索字符串。 – Stewartside
我无法使'设置'工作。 :/ – andy