Short question:

I'm not too knowledgable in php but I need a little bit of code modification help. I need to call an include to my header and footer files for any address except the main homepage. How can I do that? Thanks.

Long version:

The reason I need this is so I can include the content of my blog on my domain's homepage, but that would mean either having a double header and double footer on the homepage or having no template for any of the individual post pages or archives. I figure the easiest thing to do is just include the header/footer in most cases but somehow prevent them from being called if it's on the homepage.

I used to have two domains that shared the exact same site, and I gave them different design templates depending on the domain name. The following code "read" the domain (but not the full address) and it worked like a charm.
Code:

<?
if(preg_match("/domain1\.com/i", $_SERVER["HTTP_HOST"])) {
  $variable = "variable1";
if(preg_match("/domain2\.com/i", $_SERVER["HTTP_HOST"])) {
  $variable = "variable2";
} else {
  $variable = "variable3/";
}
?>

Of couse the variable part could be replaced with either the actual include call. Perhaps I just need to modify this code to consider the full address if possible (but I don't even understand what that /i is there for). Or perhaps there's some totally different method I haven't thought of. Is what I need possible? Thanks.

    Just get the current script name and then compare it to index.php (your homepage)

    $URL = $_SERVER['SCRIPT_NAME'];
    $script=basename($URL);
    if($script !=='index.php) {
    include('header.php');
    }

    Hope this helps.

      Write a Reply...