Reputation: 3
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?
Upvotes: 0
Views: 5408
Reputation: 270617
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; }
Upvotes: 4