So, I have a simple website with dynamically generated menu in the header and footer sections (different style for both, for footer more like a page map). I include header and footer blocks with php. So, I have a problem: I need the header and footer blocks to be seen only on other pages, not the first one- Home- page, because of different styling. I tried to do : if (content == "home") { echo .header, .footer { display: hidden;"}; but it doesn't work when I first load the page! Maybe you guys have some ideas? Thank you in advance!
Here is my code:
<?php
$languages = array("eng","lat", "ru");
$sections = array("home", "about", "cafe", "catering", "gallery", "contact");
$sectionTitles = array("eng" =>array("ABOUT US", "CAFE MENU"), "lat"=>array("PAR MUMS", "ĒDIENKARTE"), "ru" =>array("ru1","ru2",));
$lang = "eng";
$section = "home";
$content = explode("/", $_SERVER['REQUEST_URI']);
if (!empty($content[2]) && (in_array($content[2], $languages))) { $lang = $content[2];}
if (!empty($content[3]) && (in_array($content[3], $sections))) { $section = $content[3];}
$sectionTitles = $sectionTitles[$lang];
require_once ("header.php");
require_once ("$lang/$section.php");
require_once ("footer.php");
?>
Header file:
<div class="header">Some header info+menu. Not visible on first page</div>
Content file:
<div class="content">Content different for every page.</div>
Footer file:
<div class="footer">Footer info+page map. Not visible on first page.</div>
Change the require part of your code to;
if ("$lang/$section.php" === "$lang/home.php") {
require_once ("$lang/$section.php");
}else{
require_once ("header.php");
require_once ("$lang/$section.php");
require_once ("footer.php");
}
Assuming the locationon your homepage is index.php
$homepage = "/index.php";
$currentpage = $_SERVER['REQUEST_URI'];
if(!$homepage==$currentpage) {
require_once ("header.php");
}
require_once ("$lang/$section.php");
if(!$homepage==$currentpage) {
require_once ("footer.php");
}
This checks if the requested page is the homepage, if not, it will require the header and footer. Otherwise only the section is loaded.
UPDATE: If you want to hide the divs without rewriting your header and footer, check the current URL with javascript and hide the divs if the current URL is the same as that of your homepage:
var pathname = window.location.pathname;
if (pathname == 'http://www.InsertYourHomepageURL.com'){
$('.header , .footer').hide();
}
So, I did this and it works:
if ("$lang/$section.php" === "$lang/home.php") {
require_once ("headerHome.php");
require_once ("$lang/$section.php");
require_once ("footerHome.php");
}else{
require_once ("header.php");
require_once ("$lang/$section.php");
require_once ("footer.php");
}