/ Published in: PHP
Multiple loops advanved example
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// FIRST LOOP: display posts 1 thru 5 <?php query_posts('showposts=5'); ?> <?php $posts = get_posts('numberposts=5&offset=0'); foreach ($posts as $post) : start_wp(); ?> <?php static $count1 = 0; if ($count1 == "5") { break; } else { ?> <?php the_title(); ?> <?php the_content(); ?> <?php $count1++; } ?> <?php endforeach; ?> // SECOND LOOP: display posts 6 thru 10 <?php query_posts('showposts=5'); ?> <?php $posts = get_posts('numberposts=5&offset=5'); foreach ($posts as $post) : start_wp(); ?> <?php static $count2 = 0; if ($count2 == "5") { break; } else { ?> <?php the_title(); ?> <?php the_content(); ?> <?php $count2++; } ?> <?php endforeach; ?> // THIRD LOOP: display posts 11 thru 15 <?php query_posts('showposts=5'); ?> <?php $posts = get_posts('numberposts=5&offset=10'); foreach ($posts as $post) : start_wp(); ?> <?php static $count3 = 0; if ($count3 == "5") { break; } else { ?> <?php the_title(); ?> <?php the_content(); ?> <?php $count3++; } ?> <?php endforeach; ?>