PHP to get header pics and list.

Discussion in 'Web Design and Development' started by Dal123, Jul 12, 2010.

  1. Dal123 macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
    #1
    I'm designing my .com site and blog at the moment, I'm trying to grasp the basics of php and can't seem to understand too much of it on w3schools.com.

    The header on my site has a background image, and a list, I am also thinking of creating a .swf flash animation as my logo.

    I know php can $get my list but how do I go about getting my background image and where does the stylesheet get referenced. Ideally it would grab everything as one <div>.:confused:

    Also can anyone recommend decent hosting in UK (sorry to bring this up:eek:), just brief recommendation- I wouldn't recommend 123reg.co.uk as they keep changing site layout and service isn't too good. Found this http://hosting-review.com/uk.shtml?gclid=CMTC3cj65aICFR4B4wodQFFSwg

    Any advice welcomed :).
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    It's not clear what you're wanting to do. Can you elaborate?
     
  3. Dal123 thread starter macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
    #3
    Sorry for my ambiguity; my website has about 10 or so pages and I'm creating my .com site which will be a bit different but have more pages. Instead of manually entering the xhtml each time I'd like to use php to get my header (to be specific it's 'masterhead'.
    The <div>'masterhead' contains a background image, and a navigation list, but I am thinking of doing a flash animation of my masterhead to really look cool (not sure if I'm capable yet :eek:).
    I would like php to retrieve this information for me, then if the navigation list, or 'masterhead' is to change - as I have just changed my navigation list as creating a blog, I now need to tediously change all 10-15 pages with the navigation list to include my blog link:(.
    Thanks :)
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    If I'm understanding you, what you want is the include function.
     
  5. Dal123 thread starter macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
  6. Sdashiki macrumors 68040

    Sdashiki

    Joined:
    Aug 11, 2005
    Location:
    Behind the lens
    #6
    Just to reiterate with an example and not the manual:

    <?php

    include("location of file relative to site including file name");

    ?>

    Whatever happens to be inside that file will then be copy/pasted exactly where you have the <?php ?> tags.

    Navigation, headers and footers truly benefit from doing this. Youre only working with lightweight "pieces" of the site at one time and can trouble shoot much easier.
     
  7. carlosbutler macrumors 6502a

    carlosbutler

    Joined:
    Feb 24, 2008
    Location:
    London City
    #7
    What I recommend you do is create the entire layout, not content, just layout so CSS with fonts, colour schemes and then images backgrounds etc in HTML with any JS or anything else you want. Just one page.

    Then, keep that as a backup and create a blank php page called template.php. Put the top part of the HTML in a $topHTML and then bottom in $bottomHTML and then simply echo them out each time you have a new page. I also prefer to put includes like JS and CSS with absolute references.
     
  8. Dal123 thread starter macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
    #8
    Thanks for input people :D
    Bigman; what a great idea; I was just thinking I'm still going to have a lot of info and what you are suggesting eradicates a lot of work.
    I'm an absolute novice and don't have any knowledge of php or javascript, well chuffed I got the include thing to work :) thanks to you fine people.
    $topHTML to me looks like a variable, I think I get the gist of what your saying and it's going to save me a tonne of work. I don't suppose I could check out one of your sites to see the vibe? If not no worries, I can understand if not :).
    Thank-you everyone for the great advice :D.
     
  9. nesuser2 macrumors 6502

    nesuser2

    Joined:
    May 15, 2004
    Location:
    NW Ohio
    #9
    i think the best way to teach yourself is to make something that "works for you". When you think it works for you a little.......see what you can downsize. I agree with all the comments above about laying this out...then that.....then another. Until you take a class or learn the do's and don'ts..just put it in a browser and say......."why is 'this' wrong....."

    each time you can unwrong it, you will teach yourself another function or some feature of a dynamic website. Pretty soon you'll be lethal and need a book, or a class to make that next big step!
     
  10. Dal123 thread starter macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
    #10
    How about php include? Presumably must be echo or you would've said include. Why does include not work as I'm trying include now and having no joy at minute. Is there a limit as to what include can deliver?:confused:
     
  11. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #11
    You need to provide some context to your question as well as some code.
     
  12. Dal123 thread starter macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
    #12
    What I've done is taken bigman's advice and trying to create top html and (not yet created bottom but if I can get the top to work then bottom won't be a problem) I've got my top html which has a little javascript for my slideshows, masterheader, side nav bar (currently only list but just testing the theory).
    This stuff (maybe not javascript in all pages-but easy to remove) will be on all pages and it's a brilliant idea that bigman has shared and very greatful :) to use php to get it for me than to save me writing on each page like I had to on my first site.
    At first I thought it may be that I had double " " quoatations but changed them to single ' ' quoatation
    I have this as my top html in a file called 'top.php'
    HTML:
    <script src='http://www.google.com/jsapi'
        type='text/javascript'></script>
    <script src='http://www.google.com/uds/solutions/slideshow/gfslideshow.js'
        type='text/javascript'></script>
    
    <div id='container'>
    
    	<div id='masterhead'>
    	<span>Precise Formwork Limited</span>
    	</div>
    
    <ul id='nav-list'>
    	<li><a href='index.htm'>home</a></li>
    	<li><a href='services.htm'>services</a></li>
    	<li><a href='gallery.htm'>previous jobs</a></li>
    	<li><a href='links.htm'>links</a></li>
    	<li><a href='http://www.preciseformwork.co.uk/wordpress'>blog</a></li>
    	<li class='no-pad'><a href='contact.htm'>contact us</a></li>
    </ul>
    <div id='page_content'>
    <ul id='side'>
    	<li>Capping Beam</li>
    	<li>Bases</li>
    </ul>
    </div>
    </div>
    and this is what I have on my top.html file that im trying to use php include
    HTML:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta name="google-site-verification" content="KjEZ8NfGWnOxsEW_m1pW9YrMSg9fgz0ILXoLY5v3FJ8" />
    <link rel='stylesheet' media="screen" type='text/css' href='layout.css' />
    <title>Formwork</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    </head>
    
    <body>
    
    [B]<?php include(top.php);?>[/B]
    
    </body>
    </html>
     
  13. nesuser2 macrumors 6502

    nesuser2

    Joined:
    May 15, 2004
    Location:
    NW Ohio
    #13
    put all that doctype stuff in your top.php and include it as well...unless it is going to change which it generally won't so on your page you are calling top.html...we will call that page.php

    page.php:
    PHP:
    <?php 
        $pagetitle
    ='my first page'
        include 
    'header.php';
        
    ##dynamic content here##
        
    include 'footer.php';
    ?>
    you can see that your include is wrong, same syntax for require but if a require fails it kills the whole thing..sometime necessary.

    note the pagetitle is dropped in, So your header.php is:
    PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta name="google-site-verification" content="KjEZ8NfGWnOxsEW_m1pW9YrMSg9fgz0ILXoLY5v3FJ8" />
    <link rel='stylesheet' media="screen" type='text/css' href='layout.css' />
    <title><?php echo $pagetitle?></title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    </head>

    <body>

    <script src='http://www.google.com/jsapi'
        type='text/javascript'></script>
    <script src='http://www.google.com/uds/solutions/slideshow/gfslideshow.js'
        type='text/javascript'></script>

    <div id='container'>

        <div id='masterhead'>
        <span>Precise Formwork Limited</span>
        </div>

    <ul id='nav-list'>
        <li><a href='index.htm'>home</a></li>
        <li><a href='services.htm'>services</a></li>
        <li><a href='gallery.htm'>previous jobs</a></li>
        <li><a href='links.htm'>links</a></li>
        <li><a href='http://www.preciseformwork.co.uk/wordpress'>blog</a></li>
        <li class='no-pad'><a href='contact.htm'>contact us</a></li>
    </ul>
    <div id='page_content'>
    <ul id='side'>
        <li>Capping Beam</li>
        <li>Bases</li>
    </ul>
    </div>
    </div>

    footer.php:
    PHP:
    </body>
    </
    html>
    hope all this code turns out, let me know how it all looks. mainly you just need to adjust your include statement. And my other suggestion is to include more and use your variables to make the code do more work for you!
     
  14. Dal123 thread starter macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
    #14
    wow this is getting clever now :eek:.
    Thanks very much nesuser, I thought it would be really complicated to change variables and no idea how they worked, but you writing it like that has really helped.
    Thanks very much :D.
     
  15. nesuser2 macrumors 6502

    nesuser2

    Joined:
    May 15, 2004
    Location:
    NW Ohio
    #15
    I'm by no means a pro...but i get paid to write code so that must be worth something :)

    The best I can say for a beginner is to write code that works and keep teaching yourself new functions as you go and do what you can. Somewhere down the road, start digging into courses/books on it and the basics will be very clear and you can start teaching yourself all about OOP with PHP and find out how it's all done. When you figure it all out, let me know how it's all done :D
     
  16. Dal123 thread starter macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
    #16
    Thanks for help; sorry to ask for a bit more :eek:.
    The page include is working well and visible here http://www.preciseformwork.co.uk/new-site/top1.php (for now as I'll be messing around with it a lot more) I am trying to put my 'dynamic content' in the comments
    PHP:
    <?php 
        $pagetitle
    ='my first page'
        include 
    'header.php';
        
    ##dynamic content here##
        
    include 'footer.php';
    ?> 
    I want to include my paragraphs, javascript slideshows etc here, but not sure how to go about this. At the moment I have tried a simple paragraph but no joy <p>read me</p>. Anyone know what I'm doing wrong?
    Thanks :D
     
  17. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #17
    You need to learn to be more specific with what you've tried and what you need help on. You tend to write your posts as though we know what you've been coding, but we only have what you post here to go on. Below might address what you're after, but not certain.
    PHP:
    <?php 
        $pagetitle
    ='my first page'
        include 
    'header.php';
    ?>

    <script type="text/javascript" src="..."></script>
    <p>stuff</p>

    <?php
        
    ##dynamic content here##
    ?>

    <?php
        
    include 'footer.php';
    ?> 
     
  18. Dal123 thread starter macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
    #18
    Sorry I am very ambiguos, I tried applying paragraphs like so
    PHP:
    <?php
    include 'top.php';
    #<p>read me</p>#
    include 'bottom.php';
    ?>
    I'm guessing php cannot handle html in it's body hence the reason you're writing javascript. I wasn't aware of this.
    Thanks for your help on this - much appreciated :)
     
  19. Dal123 thread starter macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
    #19
    Sorry please ignore my last post, I see the problem now, needed to close the php tags. And it can handle html. Starting to get it now thanks to your help :). Thank-you very much :D.
     
  20. thejadedmonkey macrumors 604

    thejadedmonkey

    Joined:
    May 28, 2005
    Location:
    Pa
    #20
    If you want to do it without closing the php tags, look into using echo.

    You can echo""; and everything inside of echo will be parsed, so you can do something like this:

    PHP:
    $title "Hello World";
    echo
    "the title of this page is $title";
    which would display "the title of this page is Hello World"

    However, you notice that HTML tags use the double quote (") a lot, so doing something like
    PHP:
    echo"<font color="red">the title of this page is $title</font>";
    would create the problem where it stops printing after color=... (see how the color is automatically changed after the =" by the forum software too?) so instead you can use echo with single quotes (') so it looks more like

    PHP:
    echo'the title of this page is $title';
    But if you do this, you'll notice that $title is printed out, instead of Hello World. We can fix this by telling PHP to parse ONLY the $title part by doing the following:

    PHP:
    echo'<font color="red">the title of this page is '.$title.'</font>';
    This will work, so finally we can do...

    PHP:
    <?php 
    $title 
    "My Title";
    include 
    'top.php'
    echo
    '<p>read me</p>';
    include 
    'bottom.php'
    ?>
     
  21. nesuser2 macrumors 6502

    nesuser2

    Joined:
    May 15, 2004
    Location:
    NW Ohio
    #21
    Thejadedmonkey showed you advanced escaping above and you can sidestep you " with \", php will then ignore that " and let you have it in your html. If you have a ton of html and just a few variables, you can close out all your php stuff, carry on like a normal page and then <?php echo $var; ?> when you need your one or two variables. It's whatever works best in your case and whatever you learn...they all work!
     
  22. Dal123 thread starter macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
    #22
    Thanks very much everyone :D, very interesting stuff. I'm slowly picking up bits and pieces thanks to all your help.
    It's all working at the moment :).
     

Share This Page