• Resolved shagen

    (@shagen)


    Am using WP as a CMS and having trouble getting an if else statement to work properly. I am using a page template that contains a column in which I would like to change the widget area that displays depending on which page is being displayed. I still want all the pages to use the same template still. Was thinking that I could use $is_page or something with the slug to determine which page I am on and then put the various widget areas within that spot but have not had any luck as of yet. I am not much of a programmer. Basically this is what I am working from…

    <?php
    if ($is_page==(page-name))
      echo "show widget area 1";
    else
      echo "show widget area 2";
    ?>

    I can get the text ‘show widget area 1’ to show up but when I change pages it just stays there. I don’t get it and I obviously have something wrong.

    Any help that can be provided is much appreciated. Thanks for the time!

Viewing 2 replies - 1 through 2 (of 2 total)
  • check the proper syntax:

    https://codex.www.ads-software.com/Function_Reference/is_page

    <?php
    if ( is_page('page-name') )
      echo "show widget area 1";
    else
      echo "show widget area 2";
    ?>

    there might be other obstacles stopping it from working; for instance custom queries in the main content, if the widget areas are shown after the content, etc.

    just check back with your progress if you have more questions.

    Thread Starter shagen

    (@shagen)

    This is absolutely correct. You know what…. I even had seen this page and just did not understand that syntax. Now that I see how it is done it makes more sense. Your example just happens to be a little more clear to the none-programmer. Thanks for taking the time to help me out. It is seriously appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘if else help? would like to display different widget areas’ is closed to new replies.