Skip to content

Instantly share code, notes, and snippets.

View mikemcalister's full-sized avatar

Mike McAlister mikemcalister

View GitHub Profile
<?php // image gallery content
if( has_shortcode( $post->post_content, 'gallery' ) ) {
// Grab the first gallery in the post
$gallery = get_post_gallery_images( $post->ID );
$image_list = '<div class="owl-carousel">';
// Loop through each image in each gallery
foreach( $gallery as $image ) {
// Owl Carousel
function run_owl() {
// Initialize each carousel independently
$( ".owl-carousel" ).each( function() {
var $carousel = $( this ); //.owl-carousel
var $gallery = $( this ).parent(); //.owl-gallery
$carousel.owlCarousel( {
items : 1,
// This carousel works like it should, but has a little hiccup on mobile where it doesn't calculate the width properly sometimes. If you rotate your phone to landscape and back to portrait, it kicks the carousel back into place. The fix would be to trigger a refresh after the carousel is initialized, so that it recalculates but I can't get it to take.
// Helpful links:
// See the bug on mobile here: https://preview.arraythemes.com/camera/2014/01/18/test-gallery/
// Owl events: http://www.owlcarousel.owlgraphic.com/docs/api-events.html#refresh-owl-carousel
// On how to initialize: https://github.com/OwlFonk/OwlCarousel2/issues/489
// Owl Carousel
function run_owl() {
/**
* When nesting selectors (conservatively, mind you), you can add & after a selector to apply it as a parent selector.
*/
.widget-title {
font-size: 20px;
.wf-active & {
font-size: 22px;
}
.main-navigation .nav-menu > li > a {
background-color: rgba(0, 0, 0, .1);
transition: background-color 1000ms linear;
}
function theme_infinite_scroll_setup() {
add_theme_support( 'infinite-scroll', array(
'container' => 'content',
'footer' => 'page',
'posts_per_page' => 10,
) );
}
add_action( 'after_setup_theme', 'theme_infinite_scroll_setup' );
/*
* Change the posts_per_page Infinite Scroll setting from 10 to 20
*/
function theme_infinite_scroll_settings( $args ) {
if ( is_array( $args ) )
$args['posts_per_page'] = 20;
return $args;
}
add_filter( 'infinite_scroll_settings', 'theme_infinite_scroll_settings' );
function theme_infinite_scroll_setup() {
add_theme_support( 'infinite-scroll', array(
'container' => 'post-wrapper',
'render' => 'theme_render_infinite_posts',
'type' => 'scroll'
) );
}
add_action( 'after_setup_theme', 'theme_infinite_scroll_setup' );
/*
* Change the type Infinite Scroll setting from scroll to click
*/
function theme_infinite_scroll_settings( $args ) {
if ( is_array( $args ) )
$args['type'] = 'click';
return $args;
}
add_filter( 'infinite_scroll_settings', 'theme_infinite_scroll_settings' );
/**
* Add theme support for Infinite Scroll
*/
function theme_infinite_scroll_setup() {
add_theme_support( 'infinite-scroll', array(
'container' => 'post-wrapper',
'render' => 'theme_render_infinite_posts',
'type' => 'scroll'
) );
}