Multiple loops advanved example


/ Published in: PHP
Save to your folder(s)

Multiple loops advanved example


Copy this code and paste it in your HTML
  1. // FIRST LOOP: display posts 1 thru 5
  2. <?php query_posts('showposts=5'); ?>
  3. <?php $posts = get_posts('numberposts=5&offset=0'); foreach ($posts as $post) : start_wp(); ?>
  4. <?php static $count1 = 0; if ($count1 == "5") { break; } else { ?>
  5.  
  6. <?php the_title(); ?>
  7. <?php the_content(); ?>
  8.  
  9. <?php $count1++; } ?>
  10. <?php endforeach; ?>
  11.  
  12.  
  13. // SECOND LOOP: display posts 6 thru 10
  14. <?php query_posts('showposts=5'); ?>
  15. <?php $posts = get_posts('numberposts=5&offset=5'); foreach ($posts as $post) : start_wp(); ?>
  16. <?php static $count2 = 0; if ($count2 == "5") { break; } else { ?>
  17.  
  18. <?php the_title(); ?>
  19. <?php the_content(); ?>
  20.  
  21. <?php $count2++; } ?>
  22. <?php endforeach; ?>
  23.  
  24.  
  25. // THIRD LOOP: display posts 11 thru 15
  26. <?php query_posts('showposts=5'); ?>
  27. <?php $posts = get_posts('numberposts=5&offset=10'); foreach ($posts as $post) : start_wp(); ?>
  28. <?php static $count3 = 0; if ($count3 == "5") { break; } else { ?>
  29.  
  30. <?php the_title(); ?>
  31. <?php the_content(); ?>
  32.  
  33. <?php $count3++; } ?>
  34. <?php endforeach; ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.