Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alynefrancis/d53bc6b27fd4f3e649d9 to your computer and use it in GitHub Desktop.
Save alynefrancis/d53bc6b27fd4f3e649d9 to your computer and use it in GitHub Desktop.
Thanks to @kevinwhoffman for helping with the gallery filter.
<?php
/*
Template Name: (Single)Galleries Page
*/
?>
<?php get_header(); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<h1 class = "page-title"><?php the_title(); ?></h1>
<!--add introduction from the content editor on each post-->
<div class="gallery-intro">
<?php the_content(); ?>
</div> <!-- /gallery-intro -->
<!--output categories assigned to each photo via Enhanced Media Categories plugin. -->
<div class="gallery-filter">
<ul id="filters">
<li><a href="#" data-filter="*" class="active buttonlink">All</a></li>
<?php
$images = get_field('images');
$image_terms = array();
$all_used_terms = array();
foreach( $images as $image ) {
//loop over images and get which categories are being used
$image_terms = wp_get_post_terms($image['ID'], 'media_category', array('fields' => 'slugs'));
// get all categories and remove duplicates
$all_used_terms = array_unique( array_merge( $all_used_terms, $image_terms ) );
}
foreach ( $all_used_terms as $term ) {
//outputting slug so need to remove - and make first letter uppercase
//must be .$term with the dot preceeding
echo '<li><a href="#" class = "buttonlink" data-filter=".'.$term.'">' . ucwords(preg_replace('/-/', ' ', $term)) . '</a></li>';
}
?>
</ul>
</div><!-- /gallery-filter -->
<!--loop over all images available for post -->
<!--Images are part of an ACF Gallery - see documentation
http://www.advancedcustomfields.com/resources/gallery/-->
<div class="wrapper-gallery" itemscope itemtype="http://schema.org/ImageGallery">
<?php
$images = get_field('images');
if( $images ) : ?>
<?php foreach( $images as $image ) :
$terms = wp_get_object_terms($image['ID'], 'media_category');
?>
<!--echo out the tagged category as a class and data-category in the figure-->
<figure class="gallery-image image-item <?php if($terms) { foreach ($terms as $term) { echo $term->slug . ' ';}}?>"
data-catagory="<?php if($terms) { foreach ($terms as $term) { echo $term->slug . ' ';}} ?>" itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="<?php echo $image['url']; ?>" itemprop="contentUrl" data-size="<?php echo $image['width'] . 'x' . $image['height']; ?>">
<img class="" src="<?php echo $image['sizes']['large']; ?>" itemprop="thumbnail" alt="<?php echo $image['alt']; ?>" />
</a>
<figcaption itemprop="caption description"><?php echo $image['caption']; ?></figcaption>
</figure>
<?php endforeach; ?>
<?php endif; ?>
</div> <!-- gallery-wrapper -->
<?php endwhile; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment