Support » Themes and Templates » PHP if elseif problem

  • Resolved meamusta

    (@meamusta)


    I’m modifying a theme to better suite my needs, but run into a mysterious problem. In my sidebar.php I have:

    <?php
      if (is_front_page() and dynamic_sidebar('Home Page')) { }
      elseif (is_page() and dynamic_sidebar('Page Default')) { }
      elseif (is_single() and dynamic_sidebar('Single Post')) { }
      else { }
    ?>

    But for some reason this does not work. WordPress does not even compile (if that is the correct term) my sidebar.php when it looks like that. But when I remove one of the lines beginning with “elseif” statements, sidebar.php compiles and theme works nicely (only missing the removed functionality).

    Could someone please tell me what is wrong with my code.

Viewing 8 replies - 1 through 8 (of 8 total)
  • This may not address your issue – but try replacing “and” with “||”

    meamusta

    (@meamusta)

    It looks like it is the line

    elseif (is_single() and dynamic_sidebar('Single Post')) { }

    which is causing problems. Perhaps the “is_single()” function, because I tried to change the “Single Post” sidebar to another, but no luck. I’ll continue debugging tomorrow.

    meamusta

    (@meamusta)

    Replacing “and” with “||” would break the logic in the code. I want the sidebar ‘Home Page’ to be loaded to my front page, sidebar ‘Page Default’ to any other page and ‘Single Post’ when user browses to any single post.

    If I replace “and”s with “||” sidebar ‘Home Page’ would be shown in any situation.

    whooami

    (@whooami)

    Member

    meamusta

    (@meamusta)

    Could be I misused the is_single() function here. I should use the is_post() instead. is_single need an argument also to check if a particular post is displayed, but I just need to find out if any post is displayed.

    MAzCastro

    (@fmacastro)

    Perhaps what ws5f3dj7 meant was ´&&´ and not ´||´

    MAC 🙂

    novinar

    (@novinar)

    novinar

    (@novinar)

    http://www.leodata.de

    The best of webdesign.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘PHP if elseif problem’ is closed to new replies.