This is the forty eighth in a series of live lessons on using WordPress and Thesis as a Content Management System (CMS). In this lesson we change the display of posts so that any post that meets the right criteria for the recent posts category will show. Currently only 20 posts are being displayed. We fix this by adding the posts_per_page parameter to our custom loop and set it to -1 so that all posts that meet the criteria will show.
Rick: And let’s see, so… and Pam asked about pagination on the Community Library site. Let’s go there real quick. Go to custom catalog page and… oh, I forgot. We didn’t go through how to style these things either did we? I checked that off my list but obviously, we didn’t. So we’ll take on that tonight too but let’s see. Pam, I’m going to turn your microphone back on here. Hi Pam.
Pam: Good morning, Rick.
Rick: So I think what you were asking me was that in the biography section, a maximum of 20 are going to show up when… for these you know, recent biographies and if there’s more than 20, you want to paginate. You want to go to previous posts, is that right?
Pam: Yes. While we’re looking at the recent post here, if there’s more than about 20, right now, I’m not seeing any pagination at the bottom so you can see the rest of them.
Rick: And when you say more than 20, you’re referring to more than 20 per section, right?
Pam: No, just the whole thing. If we’re just talking about the recent posts that are the default for this page, it does not show all of them because after you get to about 20 of them, there’s no pagination at the bottom. Instead, it’s just telling you that there’s all there are when in fact there might be more.
Rick: Okay well that is a code fix that we’ll have to do. You can’t really do pagination that way. What we have to do is we have to fix the code so that it doesn’t stop at 20. So that it shows every post that meets the criteria, right? Every post that is within the last 60 days shows up period, even if there was 100 of them.
Pam: That would be fine, yes.
Rick: And that’s what we need to do because what this really comprised of is several loops, right? A loop essentially for each category and each of those… and if a category doesn’t have anything in it then it doesn’t show up. There’s no way to paginate that. And so, it’s not… so we can’t paginate. What we have to do is we have to fix the code and I think the way we’ll fix that code… just see if we can do that quickly right now. We’re going to open our file and let’s see… okay. No, it’s not tutorial site. Here we go. Library…
So let’s see, where is our custom… okay. So here we have it and what we would do with this is say post to show… yeah, okay. So there’s the end of the taxonomy query so I need to come down here one more time and say… it’s not post to show. It’s post per page and then I believe it’s – 0 is the right code. Post per page – 0 which means it will show everything. We could also just say post per page 100, right? And assuming that you’re never going to have 100 books come in in 60 days or that – 0… let’s just try the – 0 for a second and make sure it doesn’t crash the site. I think that’s the right… well actually, why don’t we just look at that.
If we go to the… www…let’s see. So we’re going to search for WP query and that is in the codex and we look at paging parameters, pagination parameters. So post per page… oh it’s – 1. That’s what it is. To show all posts, it’s – 1 not – 0. So – 1 would then show as many posts as met the criteria. So you noticed that when we added this additional option to this array you know, we put another… we put a comma after this tax query because that’s one element of that array. Put a comma after it and then put our… the next element of the array which is the one we just created. And then the last one doesn’t actually require a comma.
So now, our argument has 3 primary query elements. It’s got post type, it’s got the taxonomy query, and it’s got post per page. Does that make sense?