How-to show last 5 posts that are published after current post?
Explained on image below:
How-to show last 5 posts that are published after current post?
Explained on image below:
Thanks, but I don't think that only with get_posts i will resolve my primary problem.
Try it with this in your theme's functions.php:
function custom_prev_posts($limit = 5){
global $wpdb, $post;
$html = '';
$prev_posts = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.post_date < '%s' AND $wpdb->posts.post_type = 'post' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.post_date DESC LIMIT $limit", $post->post_date ) );
if($prev_posts){
$html .= '<ul>';
foreach ( $prev_posts as $prev_post ) {
$html .= '<li><a href="' . get_permalink( $prev_post->ID ) . '">' .$prev_post->post_title . '</a></li>';
}
$html .= '</ul>';
}
return $html;
}
And call the function inside the loop in single.php:
<?php echo custom_prev_posts(); ?>
Or if you want 2 previous posts:
<?php echo custom_prev_posts(2); ?>Thaaanks keesiemeijer, You are the best of ze best :) Nice work :)
You must log in to post.