How To Deal With Headers And Footers? Includes?

Discussion in 'HTML & Website Design' started by techowner1010, Feb 4, 2013.

  1. #1
    Hi there,
    I use plain HTML. I don't use DreamWeaver, although perhaps that's the solution to my problem.
    I am trying to deploy a new website with the same header and footer across each page.. I could use server side includes, but I can't because the current page is highlighted in the header (using class "current"), ex:

    <li><a href="page1.html">Page1</a></li>
    <li class="current"><a href="page2.html">Page 2</a></li>
    <li><a href="page3.html">Page 3</a></li>


    I cannot use WordPress for this site. Is there some easier way to do this, aside from copying and pasting?
     
    Solved! View solution.
    techowner1010, Feb 4, 2013 IP
  2. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #2
    Ideally you'll need to change your pages to .php format and include them using PHP.

    <?php include "includedfile.php";?>

    You could alternatively use an iFrame, but then you'll run into compatibility issues with mobile devices.

    Not entirely sure if you could do it in jQuery...
     
    scottlpool2003, Feb 4, 2013 IP
  3. techowner1010

    techowner1010 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Is using PHP for these sort of things a common practice? Just curious if I'm kind of "doing things wrong from the start".
    You know, like, sometimes I see a guy who spends 3 days hand-coding image sliders because he hasn't bothered taking the time to learn JQuery. I don't want to be that guy. :)
     
    techowner1010, Feb 4, 2013 IP
  4. #4
    It depends on your project type. If you are using ASP, there'd be a different way to do it but since you're including .html files, I'm guessing you are trying to make the jump from static to dynamic content so PHP would be the best way for you to go.

    If you're including a navigation menu for example you could do it:

    <?php include "includes/navigation.php";?>
    PHP:
    Or
    <?php require('includes/navigation.php');?>
    PHP:
    Include will put out a warning message if the file cannot be loaded whereas require will throw out a fatal error and stop the script then and there if it cannot be loaded.

    But to prevent duplicates, you could do it this way:

    <?php require_once('includes/navigation.php');?>
    PHP:
    I tend to use the include just as personal preference.

    If you're using classes for current pages, I usually have that right at the top of the page like so:

    <?php
    $class="current";
    include "includes/head.php";
    ?>
    Content
    <?php include "includes/footer.php";?>
    PHP:
    Then in your navigation, check if the page class is current.
     
    scottlpool2003, Feb 4, 2013 IP
  5. techowner1010

    techowner1010 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    Thanks!! While discussing moving to dynamic PHP... Will Google penalize me for using PHP over raw HTML?
    I hope that's not OT, since I think anyone dealing with moving toward PHP from HTML would have that concern.
     
    techowner1010, Feb 4, 2013 IP
  6. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #6
    No, PHP is Pre Hypertext Processing, it runs pretty much on the server. HTML/CSS will still be your primary markup. PHP allows you to do the cool stuff like include files and run scripts, connect to a database etc.

    It's seriously interesting to get into, just be careful to learn modern PHP (PHP5) and not PHP4.

    An interesting statistic...

    If you Google "filetype:php" you get:

    If you Google "filetype:html" you get:
    A hell of a lot of websites use PHP, but surprisingly to me, there's more HTML files than PHP files on the web.
     
    scottlpool2003, Feb 4, 2013 IP
  7. techowner1010

    techowner1010 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    Thanks! Wow, I'm also surprised at how close that ratio is... But more than PHP is so close to HTML. Thanks for your help!
     
    techowner1010, Feb 4, 2013 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #8
    deathshadow, Feb 4, 2013 IP
  9. yenerich

    yenerich Active Member

    Messages:
    697
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    75
    #9
    I recommend PHP.
    Maybe it can sounds "complicated", but its not.
    PHP is very friendly and you can find examples of every single function or step in Google in tons og pages.
    I learned PHP browsing in Google for doing everything, PHP its very easy and fun.
    In this particular case, you can use the PHP includes.
     
    yenerich, Feb 5, 2013 IP