I would really appreciate any help on this or at least a link to a tutorial :).
You can use a loop to pull multiple posts based on different criteria.
http://codex.ww.wp.xz.cn/The_Loop
You can show the most recent posts, or give them special categories like “featured” and use the loop to pull them based on that.
I agree with the guy above. There are tones of really interesting things you can do with the wordpress loop, make sure to read it and not just probe it for code, which is what I tend to do! (Not a good idea) Anyway, have fun!
http://codex.ww.wp.xz.cn/The_Loop
Thanks, Brian
Okay, I get the first example for singe loops but there are some things I am not clear on.
For the basic loop, how do I set how many posts will be displayed on the page? Does the first example (below) display ALL posts?
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
If so, how do I tell WP to create separate pages after the first 10 posts or so?
I see a way to style posts differently by category but how do I style posts differently from time they were posted. I want the latest post to be styled differently then all the rest.
Thanks … I really did read the whole tutorial I am just not very good with PHP.
You can give the latest post unique styling by isolating it within the loop using a counter to check if it’s the first post in the loop (which will be the most recent).
<?php $n = 0; ?> <-- set counter -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php if ( $n == 0 ) { ?> <-- if counter is equal to 0, you have the first post -->
<div class="entry_top"> <-- give first post unique css class -->
<?php the_content(); ?>
</div>
<?php } else { ?>
<div class="entry"> <-- give all other posts different css class -->
<?php the_content(); ?>
</div>
<?php } ?>
<?php $n++; ?> <-- increase counter -->
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
This example only pulls the content, you’d also want to add the titles, some meta, etc in both places.
Thanks a lot skylar, you really spelled it out for me!
Just a question skylar – why wouldn’t it be logical to use id instead of class for the first post since the div will only be appearing once on the page?
I know it doesn’t matter but I am always confused about this and I want to make sure I understand the purpose of classes vs. ids.
You’re totally right cscott5288, you could use id=”entry_top” since it’s only used once in the markup. (IDs are for single instances and classes are for multiple instances). However, there’s nothing saying you can’t have a single occurrence of a class, it’s just giving you the option for multiple occurrences… Sometimes I use classes because I’m not sure if I’ll want to use the same style someplace else later, but you’re definitely right with using an ID in this case, great catch!