Skip to content

Instantly share code, notes, and snippets.

@rambuvn
Created October 26, 2012 03:32
Show Gist options
  • Save rambuvn/3956712 to your computer and use it in GitHub Desktop.
Save rambuvn/3956712 to your computer and use it in GitHub Desktop.
new check of wordpress
/*-----------------------------------------------------------------------------------*/
/* Get newest post day of each category
/*-----------------------------------------------------------------------------------*/
if ( !function_exists( 'wallpress_is_new_post' ) ) :
function wallpress_is_new_post( $post_id ) {
//Get newest point of time of each category, must be newest and lessthan 3 days
$categories = get_the_category( $post_id );
foreach ( $categories as $category ) {
$date = wallpress_newest_post_category( $category->cat_ID );
$post_date = get_the_time( 'Y-m-d', $post_id );
//if date of post equal to date of recent post and date difference with current date less than 3 day
if ( ( strtotime( $post_date ) - strtotime( $date ) >= 0 ) && ( ( strtotime( $post_date ) - time() )/( 60*60*24 ) > -3 ) ) {
return true;
}
}
return false;
}
endif;
/*-----------------------------------------------------------------------------------*/
/* Get newest post in a categry
/*-----------------------------------------------------------------------------------*/
if ( !function_exists( 'wallpress_newest_post_category' ) ) :
function wallpress_newest_post_category( $category_id ) {
$args = array(
'numberposts' => 1,
'offset' => 0,
'category' => $category_id,
'post_status' => 'publish'
);
$posts = get_posts( $args );
$date = get_the_time( 'Y-m-d', $posts[0]->ID );
return $date;
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment