只需查询最新帖子并比较ID:
function wpse110867_is_latest_post( $post_id, $query_args = array() ){
static $latest_post_id = false;
$post_id = empty( $post_id ) ? get_the_ID() : $post_id ;
if( !$latest_post_id ){
$query_args[\'numberposts\'] = 1;
$query_args[\'post_status\'] = \'publish\';
$last = wp_get_recent_posts( $query_args );
$latest_post_id = $last[\'0\'][\'ID\'];
}
return $latest_post_id == $post_id;
}
主查询中的用法示例:
if( wpse110867_is_latest_post() ){
echo \'This is the latest post\';
}
要查找特定帖子类型的最后一篇帖子,请执行以下操作:
if( wpse110867_is_latest_post( get_the_ID(), array( \'post_type\' => \'my-post-type\' ) ){
echo \'This is the latest post\';
}