Skip to content

Instantly share code, notes, and snippets.

Created August 10, 2015 18:40
Show Gist options
  • Save anonymous/6cc605d8f65ad79de284 to your computer and use it in GitHub Desktop.
Save anonymous/6cc605d8f65ad79de284 to your computer and use it in GitHub Desktop.
Showing a grid of 2 items per row. Each row the image should flip sides, left to right.
//list terms in a given taxonomy (useful as a widget for twentyten)
$args = array(
'post_type' => 'staff',
'include' => $item_arr
);
$staff_query = get_posts($args);
$output .= '<div class="staff-grid">';
$i = 0;
$wrap_count = 2;
$flipswitch = false;
foreach ($staff_query as $staff) {
$i++;
if($i % $wrap_count === 1) {
$output .= '<div class="staff-grid-row clearfix">';
$flipswitch = !$flipswitch;
}
$custom_meta = get_post_custom($staff->ID);
$position_title = $custom_meta['staff_position_title'][0];
$biography = $custom_meta['staff_bio'][0];
$photo = $custom_meta['staff_photo'][0];
$last_class = ($i % $wrap_count == 0 ? 'last-item' : '');
$output .= '<div class="staff-grid-item '. $last_class .'">';
$output .= '<div class="staff-grid-item-inner">';
$bgimage = wp_get_attachment_image_src( $photo, 'staff-photo' );
if($flipswitch) {
if($photo)
$output .= '<div class="staff-grid-photo" style="background-image:url('. $bgimage[0] .');"></div>';
$output .= '<div class="staff-grid-info">';
$output .= '<h3>'. $staff->post_title .'</h3>';
if($position_title)
$output .= '<p>'. $position_title .'</p>';
if($biography)
$output .= '<p>'. $biography .'</p>';
$output .= '</div><!-- .staff-grid-info -->';
} else {
$output .= '<div class="staff-grid-info">';
$output .= '<h3>'. $staff->post_title .'</h3>';
if($position_title)
$output .= '<p>'. $position_title .'</p>';
if($biography)
$output .= '<p>'. $biography .'</p>';
$output .= '</div><!-- .staff-grid-info -->';
if($photo)
$output .= '<div class="staff-grid-photo" style="background-image:url('. $bgimage[0] .');"></div>';
}
$output .= '</div><!-- .staff-grid-item-inner -->';
$output .= '</div><!-- .staff-grid-item -->';
if($i % $wrap_count == 0) {
$output .= '</div><!-- .staff-grid-row -->';
}
}
$output .= '</div><!-- staff-grid -->';
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment