Skip to content

Instantly share code, notes, and snippets.

@pontusab
Last active August 29, 2015 13:55
Show Gist options
  • Save pontusab/8785556 to your computer and use it in GitHub Desktop.
Save pontusab/8785556 to your computer and use it in GitHub Desktop.
Get latest post on single post
<?php
// Get latest posts on single post
// Exclude current post
function GetLatestPosts( $number = 5 )
{
global $post;
$args = array(
'posts_per_page' => $number,
'exclude' => $post->ID
);
$posts = get_posts( $args );
$html = '<ul>';
foreach( $posts as $post )
{
$html .= '<li>';
$html .= '<a href="'. get_permalink( $post->ID ) .'">'. get_the_title( $post->ID ) .'</a>';
$html .= '</li>';
}
$html .= '</ul>';
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment