【问题标题】:wp_customize and selecting layoutwp_customize 和选择布局
【发布时间】:2015-05-13 19:38:08
【问题描述】:

所以我正在尝试构建一个条件语句来根据所选选项显示不同的布局。

有点麻烦。

$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; ?>

只是……没什么。我已经翻阅了法典,我看不出我做错了什么。它只是没有显示任何输出。

@Stewartside 指出我应该使用 get_setting,但我无法使其正常工作。有人吗?

【问题讨论】:

    标签: php wordpress customization


    【解决方案1】:

    get_theme_mod() 返回一个字符串,而不是布尔值。因此,您的if 语句将始终失败,因为它们期望1true0false

    您应该考虑在$wp_customize 功能中使用get_setting

    Documentation

    【讨论】:

    • 我已经研究过了,但我不知道该怎么做。我是否以正确的方式(理论上)这样做? IE。从选定的主题设置中输出不同的 php/html?
    • 理论上是的,这是使用 if 语句的正确方法。唯一的问题是 get_theme_mod 在你真的想要一个真假时检索一个字符串。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    • 2012-03-02
    • 2016-04-05
    • 2016-11-03
    • 1970-01-01
    相关资源
    最近更新 更多