Last active
August 29, 2015 13:55
-
-
Save pontusab/8785556 to your computer and use it in GitHub Desktop.
Get latest post on single post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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