Grow your CSS skills. Land your dream job.

Is it good to use header.php?

  • # May 19, 2013 at 10:08 am

    I was learning php and found a few articles, one of them was good and i understood php things from there. In that, there was a common Header.php for all files and a footer.php. Now as i am starting to create a new PHP based Forum then

    1. Should I use a common Header.php and Footer.php
    2. I want to create a fluid Layout so is it ok to use Boilerplate.css [Dreamweaver's Fluid Design option]
    3. Should i design the whole site in html and then convert it to PHP

    Really need suggestions, and I know that this is the best place to get it.

    # May 19, 2013 at 10:56 am

    Separating out commonly used components (header, footer, sidebars, any other components used in several pages across the site) is a good way to not need to repeat yourself, but ensure that there is a way for you to change it to fit the particular page (for instance having a variable somewhere that states which page it is, which creates the ``-tags).</p> <p>Okay according to whom? It’s one of those things that it’s hard to answer, because we don’t know exactly what it is you’re needing. Does it create a fluid layout in a good way, best practices, etc? Do you understand what it’s doing, at least somewhat? Does it do what you want it to do? If so, I’d say it’s quite okay.</p> <p>That’s one of the things that’s quite depending on how your workflow is. I think it’s a good idea to at least have a basic idea of the HTML/CSS that’s going into it before you start trying to use PHP to print/echo it out, yes. If you know how the various components that you use look like in HTML, it’s going to be easier to get a neater codebase.

    # May 19, 2013 at 11:10 am

    Well according to what i have designed roughly, I want a same sidebar and footer, so i guess i’ll just use these two as a separate files because i think it is better to have a different title to different pages.

    I was trying to understand what dreamweaver’s fluid design is doing. It is using separate widths for separate devices. Well that is a good thing i guess but what I am unable to understand is will it be able to work like css-tricks.com (reduction in width stacks the divs one under the other). That i am trying to figure out. If You can help me with that then it be great

    For php I thought the same

    Thanks @Melindrea for you valuable information and suggestion!

    # May 19, 2013 at 1:23 pm

    *****
    > Should I use a common Header.php and Footer.php

    Sure, many people start out learning PHP this way.

    *****
    > I want to create a fluid Layout so is it ok to use Boilerplate.css [Dreamweaver's Fluid Design option]
    …I was trying to understand what dreamweaver’s fluid design is doing

    I don’t know how Dreamweaver does this. If it works for you, go ahead and use it – you’ll need to look at what classes, etc. are available so you can write your own content to take advantage of it.

    *****
    > Should i design the whole site in html and then convert it to PHP

    first, to clarify: you *cannot* “convert HTML to PHP.” PHP is not another way to mark up webpages: it is a programming language that is very good at *writing* HTML markup. What you’re doing is writing PHP that outputs HTML. Observe:

    < ?php
    $php = “HTML”;
    echo “

    Hello, World! I’m writing $php!”;

    That’s your php script; that’s how you see it. PHP runs on your server, and anything it outputs (`print`s, `echo`s, `?>`, etc.) is sent to the visitor’s browser. Browsers read HTML:

    Hello, World! I’m writing HTML!

    *****
    To answer your question, yes: it is often very helpful to design your HTML layout first, because then you can decide which parts are static and which parts need PHP to write them:

    < !doctype html>



    Page Title

    Hello, World! I’m writing HTML!


    Most of this will be the same on every page. In this case, the page title and contents of the article are likely to change depending on the URL that was requested – so, replace those parts with variables:

    < !doctype html>



    < ?= $_page_title ?>

    < ?= $_article_content ?>


    Then, your PHP script can generate that dynamic content and insert it into your HTML *template*:

    < ?php
    # create page title
    # (based on URL, whatever)
    $_page_title = “My First HTML Template”;

    # create article
    # (retrieved from database, etc.)
    $php = “HTML”;
    $content = “Hello, World! I’m writing $php!”;
    $_article_content = “

    $content”;

    # when all your PHP work is *done*,
    # switch to output mode and insert your content into your template:
    ?>< !doctype html>



    < ?= $_page_title ?>

    < ?= $_article_content ?>


    # May 19, 2013 at 1:36 pm

    > first, to clarify: you cannot “convert HTML to PHP.” PHP is not another way to mark up webpages: it is a programming language that is very good at writing HTML markup.

    well i meant designing the whole working layout in html and then putting scripts and variables as you explained later.

    Thanks a lot for your suggestions and information. appreciate it.

    Now i can start designing my site.

    # May 19, 2013 at 2:27 pm

    >> first, to clarify: you cannot “convert HTML to PHP.” PHP is not another way to mark up webpages: it is a programming language that is very good at writing HTML markup.

    > well i meant designing the whole working layout in html and then putting scripts and variables as you explained later.

    I figured that’s what you meant. But it’s a common misunderstanding, so I thought there was no harm in mentioning it anyway.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".