Created
April 4, 2012 13:02
-
-
Save kachi/2300917 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| function is_old_post($post_id=null){ | |
| $days = 90;//日数 | |
| global $wp_query; | |
| if(is_single() || is_page()) { | |
| if(!$post_id) { | |
| $post_id = $wp_query->post->ID; | |
| } | |
| $current_date = time(); | |
| $offset = $days *60*60*24; | |
| $post_id = get_post($post_id); | |
| $post_date = mysql2date('U',$post_id->post_date); | |
| $cunning_math = $post_date + $offset; | |
| $test = $current_date - $cunning_math; | |
| if($test > 0){ | |
| $return = true; | |
| }else{ | |
| $return = false; | |
| } | |
| }else{ | |
| $return = false; | |
| } | |
| return $return; | |
| } | |
| ?> | |
| /*下記のコードで指定した日数経っている記事かどうかで条件分岐できる*/ | |
| <?php if(is_old_post()){ ?> | |
| 90日以上前 | |
| <?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment