Default Loop

The Loop, by default (read: the Loop in Default Theme) display the Posts chronologically with the most recent Post at the very top followed by less recent Posts.

The following is a sample of common usage of the Loop in theme’s index.php to have a journal-like WordPress installation.

  1. <?php get_header(); ?>
  2.  
  3. <div id="content">
  4.  
  5. <?php if( have_posts() ) : ?>
  6.  
  7. <?php while( have_posts() ) : the_post(); ?>
  8.  
  9. <div class="post" id="post-<?php the_ID(); ?>">
  10. <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
  11. <div class="meta"><?php the_category( ', ' ); ?> <?php the_author(); ?> <?php the_time('F jS, Y'); ?></div>
  12. <div class="entry">
  13. <?php the_content(); ?>
  14. </div>
  15. </div>
  16.  
  17. <?php endwhile; ?>
  18.  
  19. <?php else : ?>
  20.  
  21. <div class="error">
  22. <h2>Not Found</h2>
  23. <p>Sorry, but you are looking for something that isn't here.</p>
  24. <?php include( TEMPLATEPATH . '/searchform.php' ); ?>
  25. </div>
  26.  
  27. <?php endif; ?>
  28.  
  29. </div>
  30.  
  31. <?php get_footer(); ?>

Line 7 indicates the start of the Loop and line 17 ends it. Inside the Loop, Post data are displayed through the call of several Template Tags such as the_title(), the_category(), the_author(), and the_content(). Any other Post-related Template Tags can be placed within the Loop and the corresponding output will be displayed with each Post.

2 thoughts on “Default Loop

  1. Pingback: Rhymed Code » Asides

  2. Pingback: Wyoming Home Equity Loan

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.