The Loop starts this way:
The first part, <?php, is just standard PHP code that isn't specific to WordPress. The if (have_postsO) part is a function that queries your WordPress database to see whether you have any posts. If you do, it starts a while loop that iterates through each of your posts. Code is executed for each post in The Loop via several template tags, some of which work only within The Loop.
The code in the Loop that is responsible for displaying your posts looks like this:
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
<?php the_content('Read the rest of this entry »');
<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_categoryC, ') ?> I <?php edit_ post_linkC'Edit', '', ' I '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
This code may look intimidating, but when you know what's going on, it isn't scary at all. Most of this code is page-formatting directions, so you can ignore it. The interesting parts are the WordPress tags, because they allow you to display information from your blog. The first template tag is the_ID(), which queries the database and returns the POST_ID for use in the div tag that contains the post.
Was this article helpful?