This post is to summarize and present the code snippets of the most WordPress fundamental: the loop.
1. Set up index.php
< ?php get_header(); ?> <div id="posts-container"> // loop starts here </div> < ?php get_sidebar(); ?> < ?php get_footer(); ?>
2. Simplest loop
if (have_posts()) : while (have_posts()) : the_post(); the_content(); endwhile; endif;
Within the while loop:
- Function the_post() makes the current item in the posts collection available for use inside this iteration.
- Template tag the_content() returns the post content. more »
