What is The Loop?
The loop as the name suggests is a conditionally repeating statement that dynamically generates a string of posts within a WordPress theme. Essentially, this is the heart of the theme, no theme is without it and it controls what and where a post is presented.
What does it look like and where can I find it?
Typically, the Loop in one of our themes has the following format; all WP themes will have the loop in one form or the other (the meta portion is optional):
- <?php get_header(); ?>
- <?php while(have_posts()) : the_post(); ?>
- <div class=”post” id=”post-<?php the_ID(); ?>”>
- <h1><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>” rel=”bookmark”><?php the_title();
?></a></h1>
- <div class=”meta”>Posted on <?php the_time(’F jS, Y’) ?> under <?php the_category(’, ‘) ?> <?php if (function_exists(’the_tags’)) { ?><?php the_tags(”, ‘, ‘, ”); ?><?php } ?></div>
- <?php the_content(’Read the rest of this entry »’); ?>
- <div class=”meta”>Published by <?php the_author() ?> // <?php comments_popup_link(’Comment now »’, ‘1 Comment »’, ‘% Comments »’, ‘commentslink’); ?></div>
- <?php endwhile; ?>
- <?php get_sidebar(); ?>
- <?php get_footer(); ?>
The loop can be found within the index.php file (in 99 percent of the themes – K2 based themes have a file called theloop.php specifically for the loop code)
August 28th, 2008 at 4:17 pm
[...] Part 1 — The Loop [...]
August 18th, 2008 at 6:58 pm
[...] More here: Comment on Anatomy of a Magazine Style Premium WordPress Theme … [...]
August 18th, 2008 at 4:40 am
[...] Anatomy of a Magazine Style Premium WordPress Theme – Part 1 “The Loop” No quite sure how the wordpress loop works yet? Try checking out this article and you should have better idea of how to use the above 1001 wordpress loops. How to make a random post button This simple tutorial by WP Guy teaches you how to add a random post function into your sidebar. [...]
July 31st, 2008 at 3:51 pm
@ Chico
One loop can display posts from X and then Y, use this method from Codex.
To display archives on a monthly basis try using a plugin such as this.
July 31st, 2008 at 9:27 am
Hi
I have been looking around for good examples of multiple loops use in WP.
I am desperately trying to make something similar work for my blog. My desired setup would have:
On front page, the latest post from categoryX, followed by the latest post from categoryY then two lists outside the loop ( I think ) with the top 5 rated articles in one and the 5 most viewed posts in the other. Both of these lists would be generated by plugins (and repetition of posts not an issue on the frontpage which would not show posts in the loop after the two featured ones)
However in my archives page I would need to show all posts grouped by month.
Any help/tip/idea to modify the code above for my needs would be immensely appreciated.
C.
p.s I realise my request is similar to previous comment but still need help.