Skip to content

Instantly share code, notes, and snippets.

@drrobotnik
Created August 13, 2014 20:23
Show Gist options
  • Save drrobotnik/049855d681b2cf986750 to your computer and use it in GitHub Desktop.
Save drrobotnik/049855d681b2cf986750 to your computer and use it in GitHub Desktop.
/**
* Add theme support for infinite scroll.
*
* @uses add_theme_support
* @return void
*/
function gh_infinite_scroll_init() {
add_theme_support( 'infinite-scroll', array(
'container' => 'isoblock',
'wrapper' => false,
'render' => 'gh_isotope'
) );
}
add_action( 'after_setup_theme', 'gh_infinite_scroll_init' );
function gh_isotope(){
$html = '';
$loop_count = 0;
while ( have_posts() ) : the_post();
global $post;
$loop_count++;
$post->loop_count = $loop_count;
the_post();
$html .= load_template_part( 'content', get_post_format() );
endwhile;
$html = wp_kses_post( $html );
?>
<script type="text/javascript">
( function( $ ) {
var $container = $('#isoblock');
$items = <?php echo $html; ?>;
console.log($items);
$container.isotope( 'appended', $items );
} )( jQuery );
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment