Skip to content

Instantly share code, notes, and snippets.

@nutsandbolts
Last active August 29, 2015 14:08
Show Gist options
  • Save nutsandbolts/48c8d1e567ad9c21eae7 to your computer and use it in GitHub Desktop.
Save nutsandbolts/48c8d1e567ad9c21eae7 to your computer and use it in GitHub Desktop.
Files for Video CPT Tutorial
<?php
/**
* This file adds the custom video post type archive template to a Genesis child theme.
*
*/
//* Load Isotope
wp_enqueue_script('isotope', get_stylesheet_directory_uri() . '/js/jquery.isotope.min.js', array('jquery'), '', true);
wp_enqueue_script('isotope_init', get_stylesheet_directory_uri() . '/js/isotope_init.js', array('isotope'), '1.0.0', true);
//* Force full width content layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
//* Remove the breadcrumb navigation
remove_action( 'genesis_before_loop', 'genesis_do_breadcrumbs' );
//* Remove post info function
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
//* Remove the post content
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
//* Remove the post image
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
//* Add video body class
add_filter( 'body_class', 'nabm_add_video_body_class' );
function nabm_add_video_body_class( $classes ) {
$classes[] = 'video-archive';
return $classes;
}
//* Remove link from entry titles
add_filter( 'genesis_post_title_text', 'nabm_remove_title_links' );
function nabm_remove_title_links( $title ) {
$title = the_title( '<h1 class="entry-title">', '</h1>' );
return $title;
}
//* Display as columns (props Bill Erickson)
function nabm_video_post_class( $classes ) {
$columns = 4; // Set the number of columns here
$column_classes = array( '', '', 'one-half', 'one-third', 'one-fourth', 'one-fifth', 'one-sixth' );
$classes[] = $column_classes[$columns];
global $wp_query;
if( 0 == $wp_query->current_post || 0 == $wp_query->current_post % $columns )
$classes[] = 'first';
return $classes;
}
add_filter( 'post_class', 'nabm_video_post_class' );
//* Display Video Categories
add_action( 'genesis_before_loop', 'nabm_isotope_filter' );
function nabm_isotope_filter() {
if ( is_post_type_archive( 'videos' ) )
$terms = get_terms( 'type' );
$count = count($terms); $i=0;
if ($count > 0) { ?>
<ul id="video-cats" class="filter clearfix">
<li><a href="#" class="active" data-filter="*"><span><?php _e('All', 'genesis'); ?></span></a></li>
<?php foreach ($terms as $term ) : ?>
<li><a href="#" data-filter=".<?php echo $term->slug; ?>"><span><?php echo $term->name; ?></span></a></li>
<?php endforeach; ?>
</ul><!-- /video-cats -->
<?php }
}
//* Wrap video items in a custom div - opening
add_action('genesis_before_loop', 'nabm_content_opening_div' );
function nabm_content_opening_div() {
echo '<div class="video-content">';
}
//* Add featured image after post title
add_action( 'genesis_entry_header', 'nabm_video_grid', 9 );
function nabm_video_grid() {
if ( $image = genesis_get_image( 'format=url&size=video' ) ) {
printf( '<div class="video-featured-image"><a href="%s" rel="wp-video-lightbox"><img src="%s" alt="%s" /></a></div>', get_field( 'video_url' ), $image, the_title_attribute( 'echo=0' ) );
}
}
//* add category names in post class
add_filter('post_class', 'nabm_category_class');
function nabm_category_class($classes) {
$terms = get_the_terms( get_the_ID(), 'type' );
if( $terms ) foreach ( $terms as $term )
$classes[] = $term->slug;
return $classes;
}
//* Wrap video items in a custom div - closing
add_action('genesis_after_loop', 'video_content_closing_div' );
function video_content_closing_div() {
echo "</div>";
}
//* Remove post meta function
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
//* Remove pagination
remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' );
genesis();
//* Add new image size
add_image_size( 'video', 257, 145, TRUE );
//* Show all posts per page for video CPT
add_action( 'pre_get_posts', 'nabm_change_cpt_posts_per_page' );
function nabm_change_cpt_posts_per_page( $query ) {
if ( ! $query->is_main_query() || is_admin() || is_feed() ) {
return $query;
}
if ( is_post_type_archive( 'videos' ) ) {
$query->set( 'posts_per_page', -1 );
}
return $query;
}
jQuery(function($){
$(window).load(function() {
/*main function*/
function VideoIsotope() {
var $container = $('.video-content');
$container.imagesLoaded(function(){
$container.isotope({
itemSelector: '.video-content .entry'
});
});
} VideoIsotope();
/*filter*/
$('.filter a').click(function(){
var selector = $(this).attr('data-filter');
$('.video-content').isotope({ filter: selector });
$(this).parents('ul').find('a').removeClass('active');
$(this).addClass('active');
return false;
});
/*resize*/
var isIE8 = $.browser.msie && +$.browser.version === 8;
if (isIE8) {
document.body.onresize = function () {
VideoIsotope();
};
} else {
$(window).resize(function () {
VideoIsotope();
});
}
// Orientation change
window.addEventListener("orientationchange", function() {
VideoIsotope();
});
});
});
/* Video CPT
--------------------------------------------- */
/* Filterable Portfolio Grid
-------------------------------- */
.video-archive .archive-description {
margin-bottom: 50px;
}
.video-archive .archive-description p {
font-weight: 400;
font-size: 16px;
margin-bottom: 15px;
text-align: center;
}
.video-archive .archive-title {
font-size: 36px;
text-transform: none;
text-align: center;
}
.video-archive .site-inner .wrap {
max-width: 1200px;
}
.video-content {
margin-top: 20px;
}
.video-archive .entry {
background: #fff;
margin-bottom: 50px;
margin-left: 20px;
padding: 10px;
}
.video-content .entry .entry-title {
padding: 15px 0;
font-size: 20px;
font-weight: normal;
margin-bottom: 0;
text-align: center;
min-height: 80px;
}
.video-featured-image a {
display: block;
position: relative;
}
.video-featured-image a img {
vertical-align: top;
}
.video-featured-image a:hover {
opacity: 0.7;
}
/*
Filterable Portfolio
------------------------ */
ul.filter {
color: #999;
list-style: none;
margin-left: 0;
}
ul.filter li {
float: left;
margin-left: 1rem;
margin-left: 10px;
margin-bottom: 1rem;
margin-bottom: 10px;
}
ul.filter li:first-child {
margin-left: 0;
}
ul.filter a {
background: #333;
color: #fff;
display: block;
padding: 0.5rem 1rem;
text-decoration: none;
border-bottom: none;
}
ul.filter a:hover, ul.filter a.active {
background: #e5554e;
}
.isotope-item {
z-index: 2;
}
.isotope-hidden.isotope-item {
pointer-events: none;
z-index: 1;
}
/**** Isotope CSS3 transitions ****/
.isotope,
.isotope .isotope-item {
-webkit-transition-duration: 0.8s;
-moz-transition-duration: 0.8s;
-ms-transition-duration: 0.8s;
-o-transition-duration: 0.8s;
transition-duration: 0.8s;
}
.isotope {
-webkit-transition-property: height, width;
-moz-transition-property: height, width;
-ms-transition-property: height, width;
-o-transition-property: height, width;
transition-property: height, width;
}
.isotope .isotope-item {
-webkit-transition-property: -webkit-transform, opacity;
-moz-transition-property: -moz-transform, opacity;
-ms-transition-property: -ms-transform, opacity;
-o-transition-property: -o-transform, opacity;
transition-property: transform, opacity;
}
/**** disabling Isotope CSS3 transitions ****/
.isotope.no-transition,
.isotope.no-transition .isotope-item,
.isotope .isotope-item.no-transition {
-webkit-transition-duration: 0s;
-moz-transition-duration: 0s;
-ms-transition-duration: 0s;
-o-transition-duration: 0s;
transition-duration: 0s;
}
@media only screen and (max-width: 1200px) {
.video-archive .entry {
margin-left: 10px;
}
}
@media only screen and (max-width: 900px) {
.video-archive .one-fourth {
max-width: 45%;
}
}
@media only screen and (max-width: 500px) {
.video-content {
margin-left: 0;
text-align: center;
}
.video-featured-image {
width: 100%;
}
.video-archive .one-fourth {
max-width: 100%;
margin-bottom: 20px;
margin-left: 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment