Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wpmark
Created December 20, 2014 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmark/e969a5386589f7b57996 to your computer and use it in GitHub Desktop.
Save wpmark/e969a5386589f7b57996 to your computer and use it in GitHub Desktop.
Add a Class to Every nth Post
<?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