Making Sense of the WordPress Loop

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay good afternoon to the early birds who are just logging in or just showing up on youtube and facebook get started as you see the timer in about four and a half minutes we'll start right at the top of the hour or closely thereafter there's a slight delay a few second delay between the my broadcast and youtube's live feeds so if it's just a few seconds after one o'clock that's probably why there is that delay again we are going to be talking all about making sense of the wordpress loop and if you've never been on any of my training events over the past 15 years you will probably have never heard the wordpress loop explained through story like we are going to do today i hope you're all having a great day this is just a pre-show right now we'll start at the top of the hour this is just the introductory part of understanding the wordpress loop um so at the end of this webinar i'll explain if you want to go deeper and you want to learn at a more advanced level what we do over at wp studio but i'll leave that till the end of today's little training it's another scorcher here on the east coast nice hot humid just absolutely miserable to be outside hopefully the weather is better wherever you are so just a little over two minutes to go before we get started even at an introductory level i believe everyone who is watching this this training webinar you will understand the wordpress loop in a new way uh that it makes sense to you even if you're not a great php coder or you don't understand how code actual the intricacies of the step-by-step elements inside a you know a code or a function you will understand what the wordpress loop is and why it is so essential for every single wordpress site basically this is the core of what wordpress is and what sets it apart from other content management systems or one of the ways so since this is a live broadcast uh you can feel free to put messages or questions in the chat both on facebook and on youtube they should be fed directly to me and i can answer the questions as we go so this is not like some other training webinars you may have attended where it's all been pre-recorded all pre-done um i follow along exactly what you guys are talking about or asking questions during the live event and if you're in a replay or watching this on um just youtube you found the video if you ever have any questions you can always reach out to me at benjamin wpstudio.com and uh let me know and i'll see if i can respond as soon as possible to you all right just a few seconds to go we'll kick off right when this red button goes away well good afternoon welcome back to another live event here at wp studio we are broadcasting this live and free for the entire internet to participate in the conversation about trying to make sense of the word press loop the wordpress loop is so important it is one of the main reasons that sets wordpress apart from so many other content management systems but in order to really understand the wordpress loop we're going to need to or i'm going to need to explain this in a manner that no matter what your skill level is whether you are an expert php coder and you can just fire off code at random or whether you're kind of a hacker copy paster or maybe you've never touched php at all and you prefer just using a straight page builder to construct your website um this is all fine but understanding the wordpress loop is vital so that you can kind of give some reasoning or or approach wordpress in a more systematic method so you know what you can do with wordpress so in order for us to do this and make the wordpress loop accessible and understandable to everybody we're going to take a field trip that's right we are heading down to our local walmart if you've been on any of my trainings before you may know where this story is going i have been teaching the wordpress loop using this illustration for a long time so we're all on a field trip we are going to walmart but before we enter the store we're approached by our friendly neighborly homeless guy who sits out in front of walmart um and he asks us a question he says hey can you go get me uh deodorant i can't remember which deodorant it was that is his favorite and but i like deodorant that has the color red on it so we are now tasked with a life-saving adventure of trying to find red deodorant for our homeless friendly homeless neighbor so we go to the deodorant aisle at walmart now i don't know about you or your walmart but mine never looks this nice but for us we're now looking at all the different pieces all the different types of deodorant but we remembered our dear homeless friend said he loves red deodorant so we start going through the aisle and saying all right okay here's all these red ones let's we're not quite sure but we'll go ahead and take them all and so we'll take all the red ones at least you know one of each maybe there's a red one over here we want to grab that one and we now have all these different deodorants in our shopping cart so what do we do after we've got all our items we're going to go check out that's right so the cashier swipes each one but because we wanted to present this thing to our friendly homeless neighbor each one of the deodorants gets put into a separate walmart bag uh and so swiped it through put it in a bag grab the next one swiped it through put it in the bag and we're able to now carry out our stack of bags of different deodorant and bring it to our very happy homeless guy who now has his deodorant and we're able to present it to him so that he can see all the different deodorants that we have packaged for him well remember what we are talking about today we are trying to make sense of the word press loop well if we are trying to make sense of the word press loop hopefully all of you have realized that the story i just told you let me actually show you the script i was reading it from that's right i was reading the story i just told you that's the story oh but did you know that this is the story i just told you the query wp query if have posts while have post the post this looks like php to me and this actually is wordpress well i will tell you every single wordpress site has a variation of this type of code in every single theme now some of you might be going well that this code doesn't have anything to do with deodorant well let's jump back and see if we can understand why i told you this story so remember we took that field trip to walmart and we approached our friendly homeless guy well this is the query basically wordpress has this this function that says hey i'm gonna go get something out of the database but i need to know what you need so when we approached this homeless guy and he said hey i want some deodorant and it needs to be the color red well guess what those are the type of arguments that we are passing through to the query to go get me something something like deodorant get me color red these are all arguments and then we are saving it in this php variable well what then happened we went to the deodorant aisle and basically we said oh this is what he wants us to get so let's go ahead and grab all those red ones and this red one over here so if the query have posts so now we're looking at our shopping basket and we're saying you know what if if we have any posts now this could mean if we have any deodorant like let's say we show up here and there is no red deodorant it's only dark green white blue well the answer to this if statement is asking this question hey do you have deodorant would be no i don't have any in my bag because i didn't find any on the shelf well then we're done because we didn't find what he was looking for but let's say we did here's our red deodorant we put it in our shopping basket so now we can say while we do have those red deodorants from that query from the the question our homeless guy said so then we go check out and remember when i said that that checkout clerk is swiping each one of those deodorants putting it into a separate bag that's what's happening here so the query is grabbing the post or a single piece of deodorant and putting it in there this is where we are actually looking at the loop so if we're looking at the loop and we're now packaging each individual item we're able to then take all that stuff out of out of walmart because we've now prepared it in each of those deodorants have their own wrapper their own bag and we've been able to deliver it to the homeless guy and he walks away happy so that the next day he comes when we reset the post data he can ask another person another question of what to go into into walmart and get all right so if this has been a little bit confusing what you need to know is that this left one is the one i showed you the query basically this is in every single theme you could open up your theme right now whatever wordpress theme you're using and whether it's on an index.php or maybe you actually have a loop.php file there's any number of places it could be but you will have something that says if have posts well have posts the post on the right hand side this is the base level of the wordpress loop now why is this on the right different from this on the left well here's let me just ask you a question and for those of you who've been working with wordpress for a while you might know these answers off the top of your head but by default if you just install wordpress and you start blogging writing a few posts the front page of your wordpress site and i'm not this is basically just default you haven't put a special custom theme that does something special on the front page how many posts think to yourself how many posts show up on that front page before you have to go to the next page if you answered 10 you are correct because that is a default argument that is always going to be for every default query so the query is also go into the wordpress database and get me 10 of the latest posts not the pages not any other custom post type give me 10 of the latest posts that are published so that's why we don't have to put a query in there because if you just see if have posts while have post the post right here on the right hand side in the code it's using the default stuff if you need to change the default you change the query in our story the query was go into walmart aka the database and get me deodorant aka posts that have the color red aka the category news and return them to me that's what's happening here so that's basically every single time content is requested by a visitor to your website they come to your page your home page your archive page your 404 page not found page a query is being run the wordpress loop is being run so let let me make it a little bit more focused so you can understand this because i think it makes sense with the shopping trip to walmart for what the query is how do you go into the database and get something but the loop is just one little piece in there and i like to consider talk about the loop as a deck of playing cards so if i were to write a query that says hey go into that deck of cards and get me five cards so you get five cards put them in your hand okay and i'm gonna go back and forth between this so put those five cards in your hand so i want everybody to imagine you have these five cards in your hand okay if have cards even though it says have posts if have cards yes we have five cards in our hand so while we are having five cards in our hand give me the card a card so we give the theme the ten of hearts the theme then extracts information from just this card and it's going to be the exact same information what is the uh what is the number what is the suit what is the color all these type of things that um we can use to describe this card it would be information that would be on the card okay so that would be guess what post number one is the ten of hearts so now we go back to our loop while we have posts do we still have posts in our cards in our hand we have four of them because we already laid down the we laid down the 10. so now since we do have cards in our hand while have posts give me another card the post so we are now going to lay down the jack of hearts which means post number two is the jack of hearts see how this goes we keep going through post number three would be the queen of hearts post number four would be the king of hearts post number five would be the ace of hearts and since now we've laid all the cards down and passed them to the theme when we come to this loop while we have post do i have any cards in my hand any posts in my hand no i do not well since i don't have any more in my hand we are done with this php loop and we can basically continue on down the line in whatever code we've got and we are done because we have now been able to pass all five of the cards or the posts where it has gone out and gotten the ten of hearts jack of hearts queen of hearts so this would be in the theme it's choosing to say this is our post title this is our post content po post title post content the queen is the post title the hearts it's the post content or however your theme is creating uh and adding information so the number of cards and what cards are in your hand depends on that query because maybe i write a query that's part of the loop i write a query that says go get me the five top cards in this the heart suite in the in the suit of hearts and so that comes back to my hand so now i have a royal flush in my hand with five cards and the theme can start basically dictating what content is pulled out of the database and what parts of the content are passed to the template for displaying using the template tags well we're not going to get into template tags in this webinar if you want more information about that type of stuff and how to pull different pieces out we go into great detail at wp studio for that but this is what is happening with the wordpress loop we are querying the database getting things out now before we go further and kind of wrap this thing up this loop you might think to yourself oh well that makes sense for like the blog post page where we go in to get the database we have a whole bunch of blog posts and then we are looping through each individual item but what about an individual page so maybe i created a wordpress page called um amazing loop information and i've got tons of content on that page well in the theme uses the exact same loop to get that single page to show get the database get the content out of the database because remember with wordpress all your post titles your post content all the stuff you write in the wordpress admin is all stored in the database it's not stored in like a flat file where we just go request that file and the theme just puts that file up that's not how wordpress works well let's take a look at this let's pretend there's only the ace of hearts here the ace of hearts is the page well guess what in this query we are probably going to get a query that says go get me the page id that has this this specific page and so it returns it and we start doing this if have posts well yes i have one post the ace of hearts okay while you have that one post go ahead and the post it put it down i'll let the theme pass it through and show how to display the content that's part of that card part of that post and because that wow statement is once we've done publishing or creating that page for wordpress we say hey do you have any more cards in your hand well the answer is no because our query said only go get me that ace of hearts we no longer have any card in our hand so the loop is done so we use the wordpress loop whether it's for the archive page search pages whether it is for a single page or a single post the loop is always used because the query says what we get out of the database the loop cycles through all the different ones when we return multiple items and when we only return one item like a single page the loop only has to run once so that's what makes it really a unique situation where the loop dictates this so just as a as a quick reminder this is what we were talking about today the wp query consists of four main elements the argument for the query going back to the original field trip we took that was the request by the homeless guy for deodorant that had red labels that's very specific the query itself was our shopping trip into walmart to get the deodorant with the red labels the loop was us checking out of walmart and each time the clerk swipes the deodorant and puts it in its own bag basically that's that bag slash wrapper that the theme is using to get the the name of the deodorant the color the description the content on the all that type of stuff and each one of the items is presented with the same bag the same wrapper it's just different content in each one and then finally when we deliver off the results of our shopping trip to the homeless guy and he's got the different wall the different deodorants and they're each separate bag wrappers he can head off into the sunset perfectly happy the query gets reset so that the next homeless guy who grabs the next person to walk into walmart can make their own request and that is what the wordpress loop is now one of the things that we're doing here at wp studio is i'm offering these free introductory webinars to try and get some complex concepts out to the general public but if you want to go deeper over on wp studio and i'm just going to bring over a website here over on wp studio you can a not only sign up for ongoing events in notifications and other items just scroll down to the bottom of the page sign up i'll let you know about any free events that happen anything that goes on but if you want to go a little bit deeper because see here in our training events this is the free one we're in right now but if you want to go advanced today in literally just 40 minutes from now or 35 minutes from now we're going to spend an hour going much deeper with the wordpress loop and the query but in order to do that you got to be a member of wp studio and membership is now open with a special discount if you're looking to do this now again make sure you use the coupon because this is for the life of your subscription you will always be at the discounted rate um i'd encourage you to head on over there take a look at the new membership pricing a few more things are given to you if you're an annual member but if you don't know what any of those mean i've spent some time walking through what these are and what it means for you you can learn about different aspects of this so if you've enjoyed this type of training and you feel like hey i could learn i could learn from this type of training at wp studio we're always pushing the direction of what we're going to be doing and we have over 400 hours of training in the library which is accessible to you but if you want to take the wordpress loop further and attend the advanced training class that happens in about 30 minutes you've got to be a member of wp studio you can sign up over on wp studio and just in case that you are watching this youtube stream at a later date don't worry every single thing we do at wp studio is recorded so the moment you become a member you can go watch that advanced wordpress uh loop training course that we talk about at two o'clock well i hope you guys have a great rest of the day and i hope you enjoy for those of you who are going to join me in just a half hour our advanced take on wp on the wordpress loop so take care oh and as i said in the pre-show if you guys have any questions about any of these live trainings we do and you've made it to the end of this little video you can always email me at benjamin wpstudio.com with any of your wordpress questions or questions about the training membership so and i will try and get a response off to you as soon as possible so take care have a great rest of the day make sure you sign up for that newsletter over at wp studio so i can let you know about upcoming free events or just simply subscribe to this youtube channel because i will always put up i will always pre-schedule things normally on a monday uh and if you're you're signed up or you're subscribed to the youtube channel you'll be notified of upcoming scheduled free events take care have a great rest of the day and i will see all of you members in about a half an hour
Info
Channel: WPStudio
Views: 99
Rating: undefined out of 5
Keywords:
Id: lB6mSkRbQCI
Channel Id: undefined
Length: 29min 40sec (1780 seconds)
Published: Wed Jul 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.