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

WordPress How to Build a WordPress Plugin Connecting WordPress Plugins with 3rd Party APIs Parsing JSON Code Challenge: Part 2

suyash patankar
suyash patankar
2,310 Points

What is wrong? I am getting error 'you have not output first course'

Please let me know what is wrong in it, I have written code as per video.

plugin.php
<?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++ ): ?>

     <?   echo $my_plugin_profile->{'courses'}[$i]->{'name'}; ?>


  <?php endfor; ?>
</ul>
velochicdunord
velochicdunord
4,816 Points

FWIW, I'm having trouble with the same exercise.

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Suyash,

There are two problems with your answer. One of them is a PHP problem, the other is an HTML problem.

  1. You need to open your php block with <?php, not just <?
  2. You're just spitting out the names one after the other. You need to wrap each course name in <li></li> tags
solution.php
<?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 $my_plugin_profile->{'courses'}[$i]->{'name'}; ?>
  </li>
  <?php endfor; ?>
</ul>