Check out a free preview of the full JavaScript for WordPress course:
The "Challenge 7: Listing API Posts" Lesson is part of the full, JavaScript for WordPress course featured in this preview video. Here's what you'd learn in this lesson:

In this challenge, students retrieve a list of posts with the backbone client.

Get Unlimited Access Now

Transcript from the "Challenge 7: Listing API Posts" Lesson

>> Zac: Let's start off working through this together. And then I'll give you a little bit of time on your own to practice and see how far along you can get with things, okay? So just showing you the files real quick here.
>> Zac: It, like all the things we're doing, is going to go in stages.

[00:00:22] So the first section is going to start off, you're just going to show a list of posts, okay?
>> Zac: And then we're, no, that's 2,.1.
>> Zac: Then you're gonna pass arguments. So ultimately, we only want three posts on the page, just because it's gonna make it a little bit faster and make the page smaller, okay?

[00:00:49] So you'll put some arguments in, and then you'll write the code to save everything.
>> Zac: And then you'll write the code to edit, and then finally delete. Okay, so I'll start doing some of this with you, and then I'll turn it over to you to do on your own.

[00:01:07] And this is just reminding me one more thing I wanted to mention before you get in. This form here is coming from PHP. This is one of the things that it would have taken us, cuz you'll see, we'll use TinyMCE when we use the decoupled example, it would take us a lot of code.

[00:01:27] So to do all these different buttons and all this, that would've just been crazy in a visual editor versus a text, and hooking them with all this. So in our actual code, we have a custom template, that we’ve named custom.php. And it’s not there, it’s in the save.

[00:01:49] So what we’ve done is this code right here, and you’ll see this as you start coding along. It won’t be added till a little bit later, but notice we're checking to see, is the user logged in? And do they have the ability to edit other people's posts? There are admins, editors, authors, subscribers, contributors in WordPress.

[00:02:06] And this is checking to see that they're an editor at least. Then we're hard coding out our New Post button, and we're hard coding out our whole field. And notice this line, this is what I wanted to show you, PHP Editor will put this out. So like I said, when you're working in WordPress, there are times where it's still not a benefit to use the API.

[00:02:28] And doing something like outputting the entire WordPress editor with one line of PHP versus trying to build and customize that whole thing would just be insane. So this is an example of where a little bit PHP definitely helps. And you'll see that unlike traditional JavaScript apps, some of these is hard coded, but then everything you list-posts is just gonna be an empty div.

[00:02:51] And that'll be more like div with an ID of an app where you fill everything in