• Resolved brunerune

    (@brunerune)


    Hello, Im having a problem. I want a table with a picture to show in the sidebar on all pages except one. (http://www.mysite.com/blogg), so i set up a if else statement like this;

    <?php
    $url = $_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];
    if ($url == “http://www.MYSITE.no/blogg/&#8221;) {
    echo “<div></div>”;
    } else {
    echo “<table width=’317′ cellspacing=’0′ cellpadding=’0′ align=’left’>
    <tr>
    <td width=’317′ align=’left’ valign=’top’ style=’padding-bottom:8px;’>
    <img src=’../../../graphic/nyhet.jpg’>
    </td>
    </tr>
    </table>”;
    };
    ?>

    But that doesnt work. What have i done wrong? Are there a hack I must do since the sidebar.php are included in all the pages, and maybe cant read any url’s? Do anyone know? I use permalinks to my pages as you can see at the top. Thanks for any answer!

Viewing 2 replies - 1 through 2 (of 2 total)
  • popper

    (@julialasarte)

    Your problem is that the string you get from

    $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

    won’t include the protocol (http://) and you are incluiding it in your condition:

    if ($url == "http://www.MYSITE.no/blogg/")

    Something like this:

    $url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
     if ($url == "www.MYSITE.no/blogg/") {
        //something
    } else {
        //something else
    }

    but, It’d be better if you use wordpress built-in conditional tag: is_page()

    if (!is_page('x')){
       //do stuff
    }

    where X is the ID of the page you want to avoid. You can also use the title, or slug of the page to check. You can read about it here: http://codex.ww.wp.xz.cn/Conditional_Tags

    Hope that helps!

    Thread Starter brunerune

    (@brunerune)

    Just removed http:// and it did it. Thanks for the help!!!

    xoxo

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘If else URL problems in sidebar.php’ is closed to new replies.