Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Enhancing a Simple PHP Application Cleaning URLs with Subfolders Using Root-Relative Web Addresses

Julian Ptak
Julian Ptak
30,920 Points

AAH IT"S ALL KINDS OF BUSTED... Enhancing PHP Video - Using Root-Relative Links

I was following your steps, Randy, and the URLs don't work and the CSS disappeared from the home page... I'm sure it's my fault but I checked the header.php file and it looks exactly like your code. I'm going to check the shirts page next but here's the header.php file.

<html>
<head>
    <title><?php echo $pageTitle; ?></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 <?php if ($section == "shirts") { echo "on"; } ?>"><a href="/shirts.php">Shirts</a></li>
                <li class="contact <?php if ($section == "contact") { echo "on"; } ?>"><a href="/contact.php">Contact</a></li>
                <li class="cart"><a target="paypal" href="https://www.paypal.com/cgi-bin/webscr?cmd=_cart&amp;business=Q6NFNPFRBWR8S&amp;display=1">Shopping Cart</a></li>
            </ul>

        </div>

    </div>

    <div id="content">

I don't see what's wrong but the CSS doesn't show and the shirts link no longer works...

2 Answers

Julian Ptak
Julian Ptak
30,920 Points

Interesting! So I solved my own problem, fellow Treehousians but I think it would be worthwhile to note exactly what was wrong.

The relative-root links go up to the root directory before looking around. Well that's all fine and dandy but yesterday I completed the course on setting up my computer for Local Wordpress Development. So the relative-root links went up to the root directory on my computer and found the first CSS folder they could (which in this case happened to be a local wordpress site) and couldn't find the file in question.

Coders be wary! This could happen to you! If you have other projects besides just this one in your MAMP or XAMPP localhost, you'll need to make sure you give your links more information for this part of the project than simply the "/" character. Here's what I did to solve it:

I added "/shirts4mike/..." to each link like so:

<li class="shirts <?php if ($section == "shirts") { echo "on"; } ?>"><a href="/shirts4mike/shirts.php">Shirts</a></li>
                <li class="contact <?php if ($section == "contact") { echo "on"; } ?>"><a href="/shirts4mike/contact.php">Contact</a></li>

This gives the links a little more information. So when it goes to the root directory to snoop around, it has another clue as to where to find it. Yes... indeed... look for this link... but start looking in this project folder. So look in shirts4mike... then look for the other stuff.

Anyways, there you have it! Happy coding peeps! I hope that helped you all out!

Brandon Antonelli
Brandon Antonelli
9,689 Points

Thanks a lot for clarifying this. Had me stumped until I found your post.