WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] PHP if elseif problem (9 posts)

  1. meamusta
    Member
    Posted 5 years ago #

    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.

  2. Spencer Hill
    Member
    Posted 5 years ago #

    This may not address your issue - but try replacing "and" with "||"

  3. meamusta
    Member
    Posted 5 years ago #

    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.

  4. meamusta
    Member
    Posted 5 years ago #

    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.

  5. whooami
    Member
    Posted 5 years ago #


  6. meamusta
    Member
    Posted 5 years ago #

    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.

  7. MAzCastro
    Member
    Posted 5 years ago #

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

    MAC :)

  8. novinar
    Member
    Posted 5 years ago #

  9. novinar
    Member
    Posted 5 years ago #

    http://www.leodata.de

    The best of webdesign.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.