• cscott5288

    (@cscott5288)


    OK, so I am almost finished designing my first theme. I’ve run into some trouble though.

    I want to have multiple posts on the front page (like every blog) but can’t figure out how. I can get a single post using the_content tag in the Loop but how do I get multiple?

    I would also like to display just one full post and then, below that, multiple excerpts of posts that are placed side-by-side in divs. The html/css is all done I am just having trouble converting it to wordpress php.

    I have looked for tutorials on how to do this specifically but have had no luck. Would appreciate any help!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter cscott5288

    (@cscott5288)

    I would really appreciate any help on this or at least a link to a tutorial :).

    skylar_inmotion

    (@skylar_inmotion)

    You can use a loop to pull multiple posts based on different criteria.

    https://codex.www.ads-software.com/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.

    tisbrian

    (@tisbrian)

    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!

    https://codex.www.ads-software.com/The_Loop

    Thanks, Brian

    Thread Starter cscott5288

    (@cscott5288)

    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.

    skylar_inmotion

    (@skylar_inmotion)

    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.

    Thread Starter cscott5288

    (@cscott5288)

    Thanks a lot skylar, you really spelled it out for me!

    Thread Starter cscott5288

    (@cscott5288)

    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.

    skylar_inmotion

    (@skylar_inmotion)

    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!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Need help with designing index.php — how do I display multiple posts?’ is closed to new replies.