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?

3
  • possible duplicate of getting current URL Commented Jun 1, 2011 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? Commented Jun 1, 2011 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; } Commented Jun 1, 2011 at 19:26

1 Answer 1

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; }
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! This would work great in some instances but rather I am looking to trigger the "hidden/show" attribute in CSS for the div.
for example: if (strpos($_SERVER['REQUEST_URI'], "index.php") >= 0) { div id='left_col':hidden; div id='banner':show; div id='big_footer':show; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.