Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Simple PHP Application Creating the Menu and Footer Including the Header

jarrod Reeves
jarrod Reeves
6,357 Points

Is their anything wrong with my code?

Randy says that their shouldn't be any changes to the website. When I refreshed the page, the top navigation bar didn't come up and all the content is in list format. So on the top is the frog, then below one another is the t- shirts.

jarrod Reeves
jarrod Reeves
6,357 Points

I am also using Sublime text 2

4 Answers

Hey man, I think this is quite a common problem - if it's the one I'm thinking of.

The header will bug-out because of the $section variable not being set for the navigation. You can either go ahead and set $section on all your pages (i.e. adding $section = 'home'; on the home page) or you can check if the $section variable is set before assigning the active navigation class:

<html>

<li>
  <a href="something.php" class="<?php if (isset($section) && $section === 'something' ) { echo "active"; } ?>">
    Some Page
  </a>
</li>

if this isn't the problem you're talking about, let me know :-)

This answer helped alot with a white block I had on my shirts link in the nav bar. Thanks much!

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Jarrod;

Can you include the code you are using please? It is tremendously helpful to see what your code is. See the Markdown Cheatsheet for how to add code to a post.

jarrod Reeves
jarrod Reeves
6,357 Points

INDEX PAGE '''php <?php include ('inc/header.php'); ?>

    <div class="section banner">

        <div class="wrapper">

            <img class="hero" src="img/mike-the-frog.png" alt="Mike the Frog says:">
            <div class="button">
                <a href="#">
                    <h2>Hey, I&rsquo;m Mike!</h2>
                    <p>Check Out My Shirts</p>
                </a>
            </div>
        </div>

    </div>

    <div class="section shirts latest">

        <div class="wrapper">

            <h2>Mike&rsquo;s Latest Shirts</h2>

            <ul class="products">
                <li><a href="#">
                        <img src="img/shirts/shirt-108.jpg">
                        <p>View Details</p>
                    </a>
                </li><li>
                    <a href="#">
                        <img src="img/shirts/shirt-107.jpg">
                        <p>View Details</p>
                    </a>
                </li><li>
                    <a href="#">
                        <img src="img/shirts/shirt-106.jpg">
                        <p>View Details</p>
                    </a>
                </li><li>
                    <a href="#">
                        <img src="img/shirts/shirt-105.jpg">
                        <p>View Details</p>
                    </a>
                </li>                               
            </ul>

        </div>

    </div>

'''

CONTACT PAGE

'''php <?php include ('inc/header.php'); ?>

    <div class="section banner">

        <div class="wrapper">

            <img class="hero" src="img/mike-the-frog.png" alt="Mike the Frog says:">
            <div class="button">
                <a href="#">
                    <h2>Hey, I&rsquo;m Mike!</h2>
                    <p>Check Out My Shirts</p>
                </a>
            </div>
        </div>

    </div>

    <div class="section shirts latest">

        <div class="wrapper">

            <h2>Mike&rsquo;s Latest Shirts</h2>

            <ul class="products">
                <li><a href="#">
                        <img src="img/shirts/shirt-108.jpg">
                        <p>View Details</p>
                    </a>
                </li><li>
                    <a href="#">
                        <img src="img/shirts/shirt-107.jpg">
                        <p>View Details</p>
                    </a>
                </li><li>
                    <a href="#">
                        <img src="img/shirts/shirt-106.jpg">
                        <p>View Details</p>
                    </a>
                </li><li>
                    <a href="#">
                        <img src="img/shirts/shirt-105.jpg">
                        <p>View Details</p>
                    </a>
                </li>                               
            </ul>

        </div>

    </div>

'''

HEAD PAGE '''php <html> <head> <title> <?php echo 'Shirts 4 Mike' ?> </title> <link rel="stylesheet" href="css/style.css" type="text/css"> <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,700" type="text/css"> <link rel="shortcut icon" href="favicon.ico"> </head> <body>

<div class="header">

    <div class="wrapper">

        <h1 class="branding-title"><a href="./">Shirts 4 Mike</a></h1>

        <ul class="nav">
            <li class="shirts"><a href="#">Shirts</a></li>
            <li class="contact"><a href="contact.php">Contact</a></li>
            <li class="cart"><a href="#">Shopping Cart</a></li>
        </ul>

    </div>

</div>

<div id="content">

'''

Alexander Kapriniotis
Alexander Kapriniotis
25,897 Points

I know i may be a bit late but i just begin the tutorial and i figured out what the problem was. If you go to the php.ini file and change the short_open_tag = Off to short_open_tag = on you will be fine :)

Oh wait! I see. Still keep in mind my previous answer, I'm confident you'll encounter it soon!

The last code you gave us, the bottom most section was the header you're including?

The header has to contain, not only the navigation etc, but also the whole html <head> section. i.e. stylesheet links, page title, doctype, opening html tags etc. Everything that you want to share across these pages should be inside the header file.

Hope this helps!