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 trialGhost Nose
2,516 PointsUsing the JSON feed in the comments and the existing loop, echo out each of the course names inside the list items.
<?php
/*
{
"name": "Username",
"profile_name": "profile_username",
"profile_url": "http://myapi.net/profile_username"
"courses": [
{ "name": "WordPress Plugin Development" },
{ "name": "WordPress Theme Development" },
{ "name": "Introduction to PHP" }
]
}
*/
?>
<ul>
<?php for( $i = 0; $i < count($my_plugin_profile->courses); $i++ ): ?>
<li>
<?php echo $wp_plugin_profile->{'courses'}[$i]; ?>
</li>
<?php endfor; ?>
</ul>
Is there something here I'm not quite getting? Any advice and help would be greatly appreciated. Thanks.
3 Answers
Brad Griffin
7,003 PointsYeah, I'm stuck as well. This whole "diversion" over to parsing json with php is a bit rough. Even after rewatching the videos, and hen-pecking every solution I can think of. Then I run over to watch some videos of Jason, and find out that he doesn't exist. It's just another language that I need to learn in order to pass this challenge. :-( I don't mind learning it. But at least post a link to the right part of the json tract so that we can understand the what behind the why of this challenge :-) Still, I'm about done with this challenge. I know "posting the answer" isn't cool, but if someone would like to past the actual code WITH an explanation, I would appreciate it. Thanks! -Brad
Zac Gordon
Treehouse Guest TeacherHey,
Can you explain a little more here what you're expecting here and what is/isn't working? I'm a little unsure of exactly what you're asking.
Ghost Nose
2,516 PointsHi Zac, this question is in response to the
How to Build a WordPress Plugin > Parsing JSON Code Challenge: Part 2
When I put the code above in the Code Challenge returns "Bummer! You have not output the first course: "WordPress Plugin Development"
I probably have my php syntax wrong. Any help in telling me what I'm doing wrong is greatly appreciated. Thanks
Rob Randell
13,809 PointsYou're are missing the key value 'name',
<?php echo $wp_plugin_profile->{'courses'}[$i]->{'name'}; ?>
It should pass with that.