Created
March 10, 2012 17:50
-
-
Save kachi/2012281 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 additional_post_classes( $classes ) { | |
| global $wp_query; | |
| if( $wp_query->found_posts < 1 ) { | |
| return $classes; | |
| } | |
| if( $wp_query->current_post == 0 ) { | |
| $classes[] = 'post-first';//ループ内の最初の投稿にpost-firstというclass名を与える | |
| } | |
| if( $wp_query->current_post % 2 ) { | |
| $classes[] = 'post-even';//ループ内の偶数番目の投稿にpost-evenというclass名を与える | |
| } else { | |
| $classes[] = 'post-odd';//ループ内の奇数番目の投稿にpost-evenというclass名を与える | |
| } | |
| if( $wp_query->current_post == ( $wp_query->post_count - 1 ) ) { | |
| $classes[] = 'post-last';//ループ内の最後の投稿にpost-evenというclass名を与える | |
| } | |
| return $classes; | |
| } | |
| add_filter( 'post_class', 'additional_post_classes' ); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment