I have sticky posts on my site and this code doesn't work properly because of them. How can i show only recent posts on sidebar with codes. <ul><?php $posts=get_posts("numberposts=10&orderby=post_date&order=DESC"); foreach($posts as $post) : ?><li><a href=""><?php the_title(); ?></a></li><?php endforeach; ?></ul>
There are two ways for displaying recent post on sidebar 1.By using Coding 2.Using Widgets like add Recent Posts widget to a sidebar. try with this code :[display-posts posts_per_page="5"image_size="thumbnail"include_excerpt="true"]
Try this: <ul><?php $args = array('numberposts'=>'10'); $recent_posts = wp_get_recent_posts( $args );foreach( $recent_posts as $recent ){ echo '<li><a href="'. get_permalink($recent["ID"]).'" title="Look '.$recent["post_title"].'" >'. $recent["post_title"].'</a> </li> ';}?></ul> Code (markup): Source: http://stackoverflow.com/questions/7392289/display-recent-wordpress-posts-on-a-page