0

I am basically trying to hide a DIV on the homepage but have it show elsewhere (Controled by the URL).

DIV name "left_col"

Trying to do this using just php. How would this be done?

Ice
  • 3
  • 1
  • 2
  • possible duplicate of [getting current URL](http://stackoverflow.com/questions/5216172/getting-current-url) – AJ. Jun 01 '11 at 18:44
  • You should give more context about your problem. For example, where exactly do you want to move the DIV you hide on the homepage? – Nicolás Ozimica Jun 01 '11 at 18:45
  • Thanks nicolas, I don't want the PHP to write the code directly... I just want it to trigger the CSS atribute for the div to either "hidden" or "visible" So... something like: if (strpos($_SERVER['REQUEST_URI'], "index.php") >= 0) { div id='left_col':hidden; div id='banner':show; div id='big_footer':show; } – Ice Jun 01 '11 at 19:26

1 Answers1

4

Supposing your homepage url was index.php, something like this should work and be very easy:

// We're NOT on the home page
if (strpos($_SERVER['REQUEST_URI'], "index.php") >= 0) {
  echo "<div id='left_col'>contents</div>";
}

There are many other ways to do this, depending on the rest of your architecture, if you use templating engines, or many other factors. If you post more context for your question and your environment, I could be more specific.

EDIT To do this with CSS instead of fully suppressing output, this method specifies a class for each showing and hiding and applies it to the div.

// We're NOT on the home page
if (strpos($_SERVER['REQUEST_URI'], "index.php") >= 0) {
  $left_col_class = "showme";
}
else {
  $left_col_class = "hideme";
}

// Your html...
<div id='left_col' class='<?php echo $left_col_class; ?>'>contents</div>

// Your CSS
.hideme { display: none; }
.showme { display: block; }
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • Thanks! This would work great in some instances but rather I am looking to trigger the "hidden/show" attribute in CSS for the div. – Ice Jun 01 '11 at 18:59
  • for example: if (strpos($_SERVER['REQUEST_URI'], "index.php") >= 0) { div id='left_col':hidden; div id='banner':show; div id='big_footer':show; } – Ice Jun 01 '11 at 19:07