Build Your Own Business Website header image

Community Library Website – Part 47, Custom Loop If Have Posts

Difficulty Level -

Filed Under Topics - , , , ,

Listed Under Lesson Subjects -

Applies to - ,

Whoops, you've found some premium content!

Watch the opening clip of this video to preview it,
the full video is available to paid members.

This is the 47th in a series of live lessons on using WordPress and Thesis as a Content Management System (CMS). In this lesson we modify the custom loop for our custom catalog page. This custom loop will display recent posts organized by custom taxonomy. We use the “if have posts” conditional statement to exclude the display of taxonomy headings when there are no posts within those taxonomies that meet the criteria.

Video Transcript

And so you can see that it’s working properly except that now what we have is all of these labels showing up even if there’s nothing to display.

And so that, I believe, is the last thing we want to fix and that is to… I missed a step 6 but there will be a step 6 here which is to only display that label when it’s appropriate to display that label when there is a result.

So now what we’re going to do is come back up here to our query and so we say my query equals new wp query and we’re going to have an if statement after that. If… then we’re going to say my query and then very same syntax here. In fact, we’ll just take it instead of retyping it. If my query have post then and now what it will do is it will take this. We’re going to cut it out of that echo statement up there, we’re going to cut it out. We’re going to put it here in a loop now. So if this query has posts then put the location name in and put all the posts in. If it doesn’t have posts, this isn’t going to get printed.

And so, now we can save that. Upload it and test it. Okay so now, Bible and Reference has some, Biographies have some, DVDs… remember that where all those kids things in front of this? They don’t show anymore. Fiction has some, down to Missions, there are some. There are some in non-fiction but you can see that the way it’s working now is that we stopped this whole process. Okay we start the whole process with the label, we stop it when we don’t have any more posts that… in that location but we… as we stop it, we leave whatever blank spaces necessary then we start it again for the next one. Again, we stop it, we start it up again for the next one so on and so forth.

So this is behaving exactly the way you’d want it to behave and then all we have to do is style these headings so they look the way we want them styled.

And so that is now behaving the way we want it to behave. And this evening, I think, we’ll work on styling this some.

0 Comments… add one

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
Subscription Options
0 comments… add one

Leave a Comment