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 trialChris Andruszko
18,392 PointsJSON index has changed?
This is less of a question and more of something I noticed. I thought I'd post it in case anyone else has this problem.
This is the code Zac wrote in this video:
<?php echo $wptreehouse_profile->{'badges'}[$i]->{'courses'}[2]->{'title'}; ?>
We're accessing the third item inside the "courses" array which displayed the course titles just fine in the video (around the 9 minute mark). But maybe something has changed to the JSON file because this wasn't working for me. I inspected the JSON and found that accessing the second item in the "courses" array properly displayed the course titles:
<?php echo $wptreehouse_profile->{'badges'}[$i]->{'courses'}[1]->{'title'}; ?>
In this case, to display the project name, I have to access the "courses" array's first item:
<?php echo $wptreehouse_profile->{'badges'}[$i]->{'courses'}[0]->{'title'}; ?>
1 Answer
Andrea R
10,520 PointsI noticed this too and took a slightly different approach
<ul class="wptreehouse-badges">
<?php for( $i = 0; $i < 20; $i++ ): ?>
<li>
<ul>
<li>
<img width="120px" src="<?php echo $wptreehouse_profile->{'badges'}[$i]->{'icon_url'};?>">
</li>
<li class="wptreehouse-badge-name">
<a href="<?php echo $wptreehouse_profile->{'badges'}[$i]->{'url'};?>"><?php echo $wptreehouse_profile->{'badges'}[$i]->{'name'};?></a>
</li>
<?php if(!empty($wptreehouse_profile->{'badges'}[$i]->{'courses'})): ?>
<li class="wptreehouse-project-name">
<a href="<?php echo $wptreehouse_profile->{'badges'}[$i]->{'courses'}[0]->{'url'};?>">
<?php echo $wptreehouse_profile->{'badges'}[$i]->{'courses'}[0]->{'title'};?>
</a>
</li>
<?php endif; ?>
</ul>
</li>
<?php endfor; ?>
</ul>
Patrizia Lutz
1,449 PointsPatrizia Lutz
1,449 PointsIt seems that the JSON file structure has changed. There are now only 2 elements in the
badges
array.It also looks like the
badge->name
andbadge->url
are the same asbadge->courses[1]->name
andbadge->courses[1]->name
.What I'm using is: