Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Junior Member
    Join Date
    Sep 2006
    Posts
    23
    Member #
    13951
    Alright, so I don't know a lot about PHP, but from what I do know and what I've seen around the net, it seems like there's a way to load chunks of code into a page at the time that it's loaded in the browser. I'd like to be able to put the code for my header, navbar, and footer into there own seperate files and then just have a funcion that calls it from the page that uses it. Is there a way to do this? I'm having had time googleing it due to the vagueness of the search.

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Yes there is a way.

    First, create the seperate files (header.php, footer.php and nav.php)

    Then, inside your file that includes these files, go to the line where you want your header to appear. Type the following
    PHP Code:
    <?php include("header.php"); ?>
    Then where you want your nav to appear, type:
    PHP Code:
    <?php include("nav.php"); ?>
    Finally, where you want your footer to appear, type:
    PHP Code:
    <?php include("footer.php"); ?>
    My assumptions: all 3 files are in the same directory as the file that is including them, You may want a includes directory, in which case your include function will need to be updated with the correct path.

  4. #3
    Junior Member
    Join Date
    Sep 2006
    Posts
    23
    Member #
    13951
    ok, now in the included .php files, can I put JUST the html I want to show up, or is there some special format to that?

  5. #4
    Senior Member simpleurl's Avatar
    Join Date
    Jul 2006
    Location
    Leicester, UK.
    Posts
    150
    Member #
    13598
    Yes, the php files can be like this:

    Code:
     <div id="link1">link1</div>
    <div id="link1">link1</div>
    <div id="link1">link1</div>
    <div id="link1">link1</div>
    <div id="link1">link1</div>
    copyright 2006
    anything like that...

  6. #5
    Senior Member karinne's Avatar
    Join Date
    Dec 2003
    Location
    Aylmer QC Canada
    Posts
    1,607
    Member #
    4335
    Liked
    8 times
    Quote Originally Posted by Caj Darkmoon
    ok, now in the included .php files, can I put JUST the html I want to show up, or is there some special format to that?
    Yes just HTML is fine.

    The way I usually do it is create my whole page. Then, when I'm satisfied with the code, I cut out section and put them in another file and those will be the "included" files.

    hth
    [a web design portfolio - Currently NOT AVAILABLE for work | web design | Re-coding | PSD-to-HTML]
    I'm also on: virb - facebook - twitter - flickr - del.icio.us

  7. #6
    Junior Member
    Join Date
    Sep 2006
    Posts
    23
    Member #
    13951
    Two more questions:

    Will using this method change the way that my CSS is used?

    Will changing my .html files to .php change the way they behave?

  8. #7
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Using this method doesn't change the way your CSS will be used, but remember that you need to be including your CSS in the header. So you might have to do a little bit of voodoo there to make sure whatever files need to be included can be included.

    Changing your HTML files to PHP won't change the way they behave, except for the fact that they will be allowed to contain PHP code. However, you don't have to make your include files .php if you don't want to. The include files can be whatever you want them to be (in fact, some people name them `.inc' for `.include').

  9. #8
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Yeah, though if you decide to have some PHP code inside the files, name them file.php, as having php code in an inc file can be a security issue.

  10. #9
    Member beans's Avatar
    Join Date
    Jul 2005
    Location
    Melbourne, Australia
    Posts
    66
    Member #
    10559
    ok, silly question here-
    if you are naming your includes like [minicode]include.inc[/minicode], then... how do you call on them?
    Is it still like
    PHP Code:
    <?php include("include.inc"); ?>
    or.... how do you do it? Haha please don't laugh too hard if that is the dumbest question you've heard...
    - gah!

  11. #10
    Senior Member karinne's Avatar
    Join Date
    Dec 2003
    Location
    Aylmer QC Canada
    Posts
    1,607
    Member #
    4335
    Liked
    8 times
    Quote Originally Posted by beans
    ok, silly question here-
    if you are naming your includes like [minicode]include.inc[/minicode], then... how do you call on them?
    Is it still like
    PHP Code:
    <?php include("include.inc"); ?>
    yes
    [a web design portfolio - Currently NOT AVAILABLE for work | web design | Re-coding | PSD-to-HTML]
    I'm also on: virb - facebook - twitter - flickr - del.icio.us


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:46 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com