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 trialKohane Kagami
12,390 PointsHow can I add a link to the details page?
I created the table of item details and I want to know how to link to the page by clicking "View Details" in this page. http://testsite.gangstacat.com/catalog.php?cat=wanted
here is the code of functions.php
<?php
function get_item_html($id, $item){
$output="<li><a href=''><img src='".$item["img"] ."' alt='".$item["title"]."'/>".$id."<p>View Details</p>" . "</a></li>";
return $output;
}
function array_category($catalog, $category){
$output=array();
foreach($catalog as $id=>$item){
if($category==null OR strtolower($category)==strtolower($item["category"])){
$sort=$item["title"];
$sort=ltrim($sort, "The ");
$sort=ltrim($sort, "A ");
$sort=ltrim($sort, "An ");
$output[$id]=$sort;
}
}
asort($output);
return array_keys($output);
}
?>
Please edit this and see what i did to achieve the code formating. - KP
Konrad Pilch
2,435 PointsI'm not sure, but each page should have its unique ID so you can select just the specific one. The code you posted echo $id, it seem it could work, or at least, it shoudl be like that i guess, but i don't know 100%. Each page has it's own ID for sure.
Kohane Kagami
12,390 PointsI tried the code but it didn't work.
2 Answers
Kohane Kagami
12,390 PointsI added http://testsite.gangstacat.com/details.php?id=".$id." inside <a href''>.
Konrad Pilch
2,435 PointsWell done! ^^
Kohane Kagami
12,390 PointsThanks :)
René Sánchez
9,954 PointsHey, at the end of the video it said to look at the teachers notes for adding exactly that link that you are looking for!
Simply add this to replace the get_item_html function:
function get_item_html($id,$item) { $output = "<li><a href='details.php?id=" . $id . "'><img src='" . $item["img"] . "' alt='" . $item["title"] . "' />" . "<p>View Details</p>" . "</a></li>"; return $output; }
René Sánchez
9,954 Pointsyou have to do that in your functions.php file
sorry for the mess of code i copied and pasted :P...i recommend grabbing it directly from the teachers notes
Kohane Kagami
12,390 PointsKohane Kagami
12,390 PointsI guess I should add some code in <a href''> the URL would be something like details.php?id=<?php echo $id;?>