-
-
Save a1iraxa/7e26b539be1613326036237ddb9b4e35 to your computer and use it in GitHub Desktop.
get latest and first post in WordPress
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
/****************************************** | |
* get latest post | |
* use in loop if ( is_latest() ) { stuff; } | |
******************************************/ | |
function is_latest() { | |
global $post; | |
$loop = get_posts( 'numberposts=1' ); | |
$latest = $loop[0]->ID; | |
return ( $post->ID == $latest ) ? true : false; | |
} | |
/****************************************** | |
* get first post | |
* use in loop if ( is_first() ) { stuff; } | |
******************************************/ | |
function is_first() { | |
global $post; | |
$loop = get_posts( 'numberposts=1&order=ASC' ); | |
$first = $loop[0]->ID; | |
return ( $post->ID == $first ) ? true : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment