1

So I'm trying to build a conditional statement to display different layouts depending on the option selected.

Having a bit of trouble.

$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.

So here we have a couple of choices.

$wp_customize->add_section('layout' , array(
    'title' => __('Layout','Ari'),
)); // add our layout section in the customize panel.

Displaying our layout.

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

Just...nothing. I've trawled through the codex and I can't see what I'm doing wrong. It just doesn't show any output.

What about get_setting? How would I write a conditional for that?

1 Answer 1

1

You need to check against the value of layout:

if ( get_theme_mod( 'layout' ) === 'stream' ) {
    // Stream
} elseif ( get_theme_mod( 'layout' ) === 'grid' ) {
    // Grid
} else {
    // Fallback
}
3
  • Don't you need an endif?
    – andy
    Commented May 18, 2015 at 22:36
  • Wait nvm I'm being an idiot. } duh. Is this the correct/best way to do it, btw? Seems like there's lots of different ways to mess with the customize options.
    – andy
    Commented May 18, 2015 at 22:40
  • Looks okay to me. Commented May 18, 2015 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.