Last active
September 16, 2016 18:33
-
-
Save neilgee/d7870d1f59f63f4bacfb to your computer and use it in GitHub Desktop.
Masonry in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Masonry load scripts | |
function wpb_masonry_scripts_styles_alt() { | |
wp_enqueue_script ( 'masonry'); //jqueryless | |
} | |
add_action( 'wp_enqueue_scripts', 'wpb_masonry_scripts_styles_alt' ); | |
//Masonry Style javascript | |
function wpb_js_masonry() { ?> | |
<script> | |
var container = document.querySelector('.home .content'); //set container | |
var msnry; | |
// initialize Masonry after all images have loaded | |
imagesLoaded( container, function() { | |
msnry = new Masonry( container, { | |
itemSelector: '.entry', //set target | |
}); | |
});</script> | |
<?php | |
} | |
add_action( 'wp_footer','wpb_js_masonry', 20);//add priority to push it below masonry script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Settings Masonary | |
jQuery( document ).ready( function( $ ) { | |
$( '.content' ).masonry( );//targets the posts container | |
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*override masonry*/ | |
.archive-pagination { | |
position: relative !important; | |
top: 0 !important; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//shift pagination out of container | |
jQuery(function( $ ){ | |
$('.archive-pagination').insertAfter(".content-sidebar-wrap"); | |
}); | |
//ref- http://api.jquery.com/insertafter/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Masonry load scripts | |
function wpb_masonry_scripts_styles() { | |
wp_enqueue_script ( 'jquery-masonry'); | |
wp_enqueue_script ( 'masonry-init' , get_stylesheet_directory_uri() . '/js/masonry-init.js', array('jquery-masonry'), '1', true ); | |
} | |
add_action( 'wp_enqueue_scripts', 'wpb_masonry_scripts_styles' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.home .entry { | |
background: #f8f9fa; | |
margin: 0 1.5% 30px !important; | |
padding: 3%; | |
width: 100%; | |
} | |
/* 3 Up on devices ipad portrait plus */ | |
@media only screen and (min-width: 768px) { | |
.home .entry { | |
width: 30%; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment