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

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
}
  • Don't you need an endif? – andy May 18 '15 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 May 18 '15 at 22:40
  • Looks okay to me. – TheDeadMedic May 18 '15 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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