Forums

[resolved] Trouble with conditional statement for front page, to show sidebar (3 posts)

  1. webbcity
    Member
    Posted 7 months ago #

    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!

  2. Chip Bennett
    Member
    Posted 7 months ago #

    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' ) )
  3. webbcity
    Member
    Posted 7 months ago #

    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.

Reply

You must log in to post.

About this Topic