Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I understand that there is a way to have the loop display multiple ways on one page without using multiple loops... Or in other words something like:

<?php if (have_posts()) : while (have_posts()) : ?>
<!-- Code for the First Post -->
<?php else: ?>
<!-- Code for Posts 2-4 -->
<?php else: ?>
<!-- Code for Posts 5-12 -->
<!-- stuff to close loop -->

Problem is that I don't really know php well, and I have no idea how to have it count posts and how to tell it for the first post do X, for posts 2 through 4 do X, and for posts 5 through 12 do X... If anyone can point me to a clear tutorial or let me know what PHP is necessary, I'd really appreciate it.

Thanks in advance!

share|improve this question
2  
You should read about if/else/while/for/foreach on php.net first. This surely helps you getting 90% of your Qs out of your way in less than 20 minutes. –  kaiser Jan 19 '12 at 4:09
    
I understand how if/else statements themselves work, it's just I don't understand how telling Wordpress to count and for x# of posts works... –  cw02 Jan 19 '12 at 13:40
add comment

1 Answer

this is your answer... however like Kaiser said, you should really take some time to read a little...

 <?php 
 $i=0;  
 if ( have_posts() ) while ( have_posts() ) : the_post();
      if($i==0) { ?>

         // YOUR FIRST POST CONTENT

      } else if(($i==1) || ($i==2) || ($i==3)) {

         // POST 2, 3, 4

      } else {

         // everything else

      }
 $i++;
 endwhile;

This is a fast answer and is not the ideal approach, but it will solve your problem...

share|improve this answer
    
Thanks, this helps a lot. I've been trying to read but I'm having difficulty understanding how counting works... And php.net isn't exactly easy to understand. –  cw02 Jan 19 '12 at 14:12
    
if the answer worked for you, please remember to mark it, so other people will be able to find a solution for similar problems –  andresmijares25 Jan 19 '12 at 15:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.