0

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>
Kristine
  • 737
  • 2
  • 9
  • 22
  • hi please check the link http://stackoverflow.com/questions/3952590/php-how-to-find-application-root .. will be helpful for you – Renjith May 07 '14 at 09:41

3 Answers3

1

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();
}
timo
  • 2,119
  • 1
  • 24
  • 40
  • The problem is: I need to include those files, but I need divs with class .header and .footer to be hidden. I have all the head block in header.php file! – Kristine May 07 '14 at 10:03
  • I guess I can make different header and footer files for home page and for others. Thank you! – Kristine May 07 '14 at 10:04
  • @Kristine Does your homepage always have the same URL i.e. no variables in the URL? I could write a jquery variant that hides classes `header` and `footer` when this URL is active. – timo May 07 '14 at 10:13
1

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");
}
Pwner
  • 791
  • 5
  • 16
0

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");
}
Kristine
  • 737
  • 2
  • 9
  • 22