I just jumped in and started moving code around. It really helped me understand what the loop was, don’t know I could have understood it as well from just reading about it.
The loop can be seen as the fuction of passing instructions to all content that is output as the result of a query.
For example, If you put php code to show a link to a post’s category in “the loop” it will apply that code to every post that get’s called in the query. or, every post in the loop. All posts will show that link.
Think of it this way:
Say you had two queries on a single page, and one has such a category link in it’s loop, and the other query does not. The posts which are output by the first query have the category code “in the loop” but for the second query, that code is “outside” of it’s loop. So it won’t get applied to the posts which it outputs. Get it?
You know if your code is in the loop by knowing what code for the loop looks like. the twenty ten theme actually says “end of the loop”. If you place code outside the loop code, it does not get applied to the posts that are output in the query. So the php to show the category link wouldn’t do anythng if outside the loop.
Create an if statement, just put in category slugs that exist on your site.
<?php if (in_category('category-slug')) { ?>
this text will show up if the post is in this category
<?php } ?>
Can you tell me if that conditional code is to be used “in the loop”? I’ll tell you it goes in single.php. Can it do what it should do if it is outside the loop? can it go after the content is output? or should it go before? This text could have been code which could be applied according to the same conditional.
give it a try, put it in and out of the loop and see.
just don’t use a live site of course.
let me know how it goes and we’ll get to the next assignment. I’m learning too:)