Duplicate post in my recent posts
-
I’m trying to display my most recent post as an excerpt and 4 other posts as links. I used the code from Multiple_Loops_in_Action to display 2 lists of posts with the $do_not_duplicate = $post->ID bit and every thing is working just fine, except that the most recent post is showing up in the second list as well. I’m new to php and can’t figure out where I am going wrong.
Here is my code:
<?php $my_query = new WP_Query('category_name=inspiration&posts_per_page=1'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID;?> <li><a href="<?php echo get_permalink(); ?>"> <?php the_title( '<h2>', '</h2>' ); ?></a> <?php the_excerpt(); ?></li> <?php endwhile; ?> <!-- Do other stuff... --> <?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; ?> <?php $args = array( 'numberposts' => '5' ); $recent_posts = wp_get_recent_posts(); foreach( $recent_posts as $recent ){ echo '<li><h2><a href="' . get_permalink($recent["ID"]) . '" title="'.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> </h2></li> '; } ?> <?php endwhile; endif; ?>And here is a link to the site (the code is in the sidebar.php):
http://www.dernet.co.uk/TempAYLthanks!
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘Duplicate post in my recent posts’ is closed to new replies.