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 trialorange sky
Front End Web Development Techdegree Student 4,945 Pointswhat happens after I click the link?
Hello!
1)This code below is from the inc/header.php; I understand that it is supposed to cause the the link to be underlined when clicked, but I wonder if the variable $section with its value "shirts" get sent to the url as we move from contact.php to shirts.php?
2) Is "on" a javascript keyword or is it a variable we create and style in css so that it underlines the link when click on.
Cheers
<li class="shirts <?php if($section == "shirts") { echo "on";} ?>"><a href="shirts.php">Shirts</a></li>
Edit: I edited your post to make the code visible, please click edit so you can see how i did it. Hugo Paz
4 Answers
Hugo Paz
15,622 PointsHi orange sky,
The variable $section is not passed in the url, its is set on each page right at the top, "index.php", "shirts.php"...
The 'on' is just a class to be defined in css. If you run that code you get:
<li class="shirts on"><a href="shirts.php">Shirts</a></li>
So that list element as the 'shirts' and 'on' css classes.
orange sky
Front End Web Development Techdegree Student 4,945 PointsHello Hugo,
Thanks you have helped me clear some confusion, I just have a few related questions:
1) WHy is it that when I comment //$section = "contact", and I run the code, the contact link is alway underlined. Can you please explain in basic 101 language for dummies hahaha :) what the $section = "contact", (which is right above include() )do to prevent the contact link from always being underlined. I cant seem to see the connection
2) This one might be a little hard to answer, but would you happen to know why after adding if($section == "shirts"){ echo "on";}, the shirts's entire link is all white, not just the underlined line.
Cheers!
<?php
$pageTitle ="Contact Mike";
//$section = "contact";
include('inc/header.php');
?>
<div class="section page">
<h1>Contact </h1>
</div>
<?php
include('inc/footer.php');
?>
Hugo Paz
15,622 Pointsif you comment out $section = "contact", the if condition fails
if($section == "shirts") { echo "on";}
which means the css class 'on' is never attached to that li.
As for your second question, have a look the css files, search for the class 'on'
orange sky
Front End Web Development Techdegree Student 4,945 PointsHello Hugo,
Let me just focus on the first one.
I have been toying with commenting and uncommenting, and believe it or not, following the code below, the shirt link does not get highlighted, but the conctact link gets highlited, even though I dont have $section = "contact' in the contact.php. This is a mystery to me.
<li class="shirts "><a href="shirts.php">Shirts</a></li>
<li class="contact <?php if($section == "contact" ){echo "on";}?> "><a href="contact.php">Contact</a></li>
<?php
$pageTitle ="Contact Mike";
include('inc/header.php');
?>
<div class="section page">
<h1>Contact </h1>
</div>
<?php
include('inc/footer.php');
?>
Hugo Paz
15,622 PointsBy highlighted do you mean turning yellow?
orange sky
Front End Web Development Techdegree Student 4,945 PointsThat's true too, there is that yellow, but what is really confusing to me is the underlined that under the links when contact.php doesnt have $section = "contact" and shirts.php doesn have $section ="shirts", but the li tags show this:
<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 href="#">Shopping Cart</a></li>
</ul>