problem with get_posts() effecting the loop
-
I’m using get_posts() to create a secondary list of posts on a page rather than another loop as suggested in the docs, however it’s changing the existing loop from displaying the correct page contents to the first post that get_posts(). Am i missing something here?
first list:
$posts = get_posts(); foreach( $posts as $post ) : setup_postdata($post); ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <p><?php the_date(); ?></p> <h3 class="entry-title"><?php the_title(); ?></h3> <div class="entry-content"> <?php global $more; $more = 0; echo strip_tags(get_the_content()); ?> </div> </div> <?php endforeach; ?>
main loop:
<?php wp_reset_query(); ?> <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <?php if ( !is_front_page() ) { ?> <h1 class="entry-title"><?php the_title(); ?></h1> <?php } ?> <div class="entry-content"> <?php the_content(); ?> </div> </div> <?php endwhile; ?>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘problem with get_posts() effecting the loop’ is closed to new replies.