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