• Resolved webbcity

    (@webbcity)


    Here’s the situation:

    I have a sidebar in a mobile theme that I only want to show on the front page. My knowledge of PHP is a little fuzzy here. I thought I could combine the conditional statement with the existing sidebar code like so:

    <?php if (is_front_page() && !function_exists('dynamic_sidebar')
    || !dynamic_sidebar('home-video-link') ) : ?>
    <?php endif; ?>

    But it doesn’t work. What am I doing wrong? I just took what was there and added the is_front_page() && to the front of. Is that wrong?

    Thanks for any assistance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • If I had to guess, I’d say it’s a problem with your Boolean logic syntax.

    Change this:

    if (is_front_page() && !function_exists('dynamic_sidebar')
    || !dynamic_sidebar('home-video-link') )

    …to this:

    if ( is_front_page() && ( ! function_exists( 'dynamic_sidebar' )
    || ! dynamic_sidebar( 'home-video-link' ) ) )

    Alternately, get rid of the ! function_exists( 'dynamic_sidebar' ) altogether. The dynamic_sidebar() function was defined in about version 2.8 of WordPress, so backward-compatibility is no longer necessary. So, you could simplify it as:

    if ( is_front_page() && ! dynamic_sidebar( 'home-video-link' ) )

    Thread Starter webbcity

    (@webbcity)

    Brilliant, thanks so much! That did the trick. I’ll look up that dynamic sidebar function too, so I have a better understanding of it. Many thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trouble with conditional statement for front page, to show sidebar’ is closed to new replies.