get_posts creating 3 loops instead of 1
-
I’m trying to create an archive page that shows past posts from a certain category, sorted by month. This code works but the page appears to be running the loop 3 times instead of 1. See link
<?php // Declare some helper vars $previous_year = $year = 0; $previous_month = $month = 0; $ul_open = false; // Get the posts $myposts = get_posts('cat=16&numberposts=-1&orderby=post_date&order=DESC'); ?> <?php foreach($myposts as $post) : ?> <?php // Setup the post variables setup_postdata($post); $year = mysql2date('Y', $post->post_date); $month = mysql2date('n', $post->post_date); $day = mysql2date('j', $post->post_date); ?> <?php if($year != $previous_year || $month != $previous_month) : ?> <?php if($ul_open == true) : ?> </ul> <?php endif; ?> <h3><?php the_time('F Y'); ?></h3> <ul class="newslist"> <?php $ul_open = true; ?> <?php endif; ?> <?php $previous_year = $year; $previous_month = $month; ?> <li class="<?php echo c2c_get_custom('Link Type'); ?>" style="list-style-type:none"><a href="<?php echo c2c_get_custom('URL'); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul>
I’ve tried resetting the loop before and after this piece of code with no luck. Any suggestions would be much appreciated!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘get_posts creating 3 loops instead of 1’ is closed to new replies.