Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: CSS layout using PHP?

  1. #1
    Join Date
    Jul 2007
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default CSS layout using PHP?

    I originally had coded my site in CSS, but in realizing some very basic problems with it, it was recommended that some aspects of it (specifically the header with the navigational section and the footer) would probably be better if I handled them as PHP includes.

    However, not being terribly familiar with PHP (although, my host does allow for it), I was wondering if I could use something similar to this: http://www.dynamicdrive.com/style/cs...rizontal-menu/

    but in my PHP include file and is it possible to just reuse my existing CSS code and somehow just change the extension to PHP or would I need to completely recode it?

    Any and all help will be appreciated.

  2. #2
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes you can reuse the exact code...
    basically what you need to do is take all of your header code and place it in a separate file (eg. header.php). Then you will go to where the header code originally was and replace it with an include statement to that file.

    <? include("header.php"); ?> (use the question mark brackets to show where php code starts and ends)


    so for example, if this is what you originally had:

    PHP Code:
    index.php
    <header code>blah blah blah blah</header code>
    <
    navigation code>more blah blah blah</navigation code>
    <
    body code>this is the main body of the page</body code>
    <
    just some other code>1 2 3 4 5</just some other code
    you will then change it to this:
    PHP Code:
    header.php
    <header code>blah blah blah blah</header code>

    navigation.php
    <navigation code>more blah blah blah</navigation code>

    index.php
    <? 
    include("header.php");
    include(
    "navigation.php");
    ?>
    <body code>this is the main body of the page</body code>
    <just some other code>1 2 3 4 5</just some other code>
    i hope that made sense. remember that pages that you use to include the php must have a php extension.

  3. #3
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    Using PHP???? that would be not so smart... you just have to do this...
    Put that in the head of the page...
    Code:
    <link rel="stylesheet" href="stylesheet.css" />
    Make sure all your css code is put in without the
    Code:
    <style></style>
    tags...
    Putting it in includes is just something that I have not tried yet..

    Hope this helps man

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Use an external stylesheet, definitely.
    But if you do need something dynamic using PHP (not sure what that would be), then this would apply:
    http://www.dynamicdrive.com/forums/s...ad.php?t=21617
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jul 2007
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Among the reasons I had originally been told that I should use PHP is because I was having some problems with the navigation where my layout was concerned.

    I had it set up so that it was originally using divs with the first div set aside for my banner with the navigation bar, which was similar to the one in the link I posted. The next "div" had been where I wanted the links to my content to open up on the page. The third and last div was for my footer. I wanted to be able to re-use my navigation/banner along with the footer and have them show up on every page, but without having to actually add them to every page directly (ie somehow keep them separate) so they wouldn't have to constantly reload when it wasn't necessary. Sort of like a "frames" effect, without the actual use of frames. Needless to say, I couldn't get it working this way.

    In other words, it would have looked something like this:

    -------------------
    Header with banner and
    Navigation with links
    -------------------
    Content/where links were to open up



    -------------------
    Footer with copyright info/Terms of use link
    -------------------

    Someone had recommended to me to chop my site up as far as the header (with the navigation menu) and footer and use PHP includes for each page I had for my site (the first recommendation had been to use SSI, however, my host doesn't offer support for it). However, again, not being familiar with PHP I wasn't sure how to go about it as far as the coding for the header and footer pages or if I could even keep my existing coding that I extracted from my original layout for both sections or whether it would somehow need to be redone, which is part of the reason I was asking for help here.

    When I asked for help with this layout the last time (different section of this forum, of course), I was told I'd either need to use frames (which I'd just as soon avoid and had been advised against) or make use of AJAX (which I also am not very familiar with) and it was made to sound like there wasn't really a straight CSS/HTML "solution" to my situation (the same person--someone not on this board--who recommended using PHP includes to me, had told me the same thing), so now I'm confused as to what to do or how to try and salvage my layout.

    I do appreciate all the help, though.

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Ok, then you can use PHP to include those parts of the page. Good idea in that case.
    But that's not CSS. That's just html in your page.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by littleEd View Post
    index.php
    <?
    include("header.php");
    include("navigation.php");
    ?>


    remember that pages that you use to include the php must have a php extension.
    no they do not... you can include anythign you would like... you just need to make sure the file you want to include is on the server...

    if you have some code, that you want protected (DATABASE / PASS variables)/ must be processed on the server side, then yes you would need to use php extensions, but you can include / require any file name / extension that your head can think of, just as long as you get the path correct.

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    "pages you USE TO INCLUDE", not the included pages.
    Any page with <?php ?> tags on it must end with .php; other files can be included (.php, .htm, .txt, .inc, etc.)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jul 2007
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    So then, and this is going to sound like a potentially stupid question, how can I convert the code I used for my header and footer files (or do I even need to)? I realize that with the content pages I'll be adding them as includes for, it would have to appear something like the examples above. However, either I'm wondering if they need to somehow be recoded or what I'm doing wrong as I can't seem to get either my footer nor my header to show up for me on my test page.

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    1. PHP:
    Your server must have PHP installed/enabled.
    2. Page:
    Your page must end with .php and use <?php ?> tags.
    3. Included pages:
    Nothing special here, as long as they exist.

    PHP includes are very simple. They directly take the contents of those pages and place it into the current page at that location:

    Code:
    TEST.txt:
    abcdef
    _________________
    
    TEST.php:
    123<?php include('TEST.txt'); ?>456
    If you were to visit TEST.php, the output source code would be "123abcdef456". Simple as that.


    Your header and footer will be taken and directly input into the page. As such, consider what they should have in them. It would be easy to write a full page, then cut out the sections you want included, replace with a tag, then save those contents to the included page.

    Your includes pages, then, should be just chunks of html, like on the page. They shouldn't be full working pages-- no <html><body> tags, etc.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •