Created
December 20, 2014 14:55
-
-
Save wpmark/e969a5386589f7b57996 to your computer and use it in GitHub Desktop.
Add a Class to Every nth Post
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
<?php | |
/* setup a counter for the sections to use as class */ | |
$counter = 0; | |
/* loop through each section */ | |
foreach( $sections as $section ) { | |
/* increment the counter */ | |
$counter++; | |
/* start a classes variable */ | |
$classes = 'section page-section'; | |
/* add classes for section colour depending on the count value */ | |
if( 1 == $counter % 3 ) { | |
$classes .= ' section-white'; | |
} elseif( 2 == $counter % 3 ) { | |
$classes .= ' section-lightgrey'; | |
} elseif( 0 == $counter % 3 ) { | |
$classes .= ' section-midgrey'; | |
} | |
/* if this is the first section */ | |
if( $counter == 1 ) { | |
$classes .= ' section-first'; | |
} | |
/* if this is the last section */ | |
if( $counter == $total_sections ) { | |
$classes .= ' section-last'; | |
} | |
?> | |
<section class="<?php echo esc_attr( $classes ); ?>"> | |
<!-- // sectoion content here --> | |
</section> | |
<?php | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment