-
-
Save 10h30/34b537a8e6f449e2ac90 to your computer and use it in GitHub Desktop.
Pinterest-like Masonry layout for Posts page and Archives in Genesis. Details: http://sridharkatakam.com/using-masonry-genesis-pinterest-like-layout/
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 | |
//* Do NOT include the opening php tag | |
// ================================================================= | |
// = Pinterest-like Masonry layout for Posts page and Archives = | |
// ================================================================= | |
//* Enqueue and initialize jQuery Masonry script | |
function sk_masonry_script() { | |
if (is_home() || is_archive()) { | |
wp_enqueue_script( 'masonry-init', get_stylesheet_directory_uri().'/js/masonry-init.js' , array( 'jquery-masonry' ), '1.0', true ); | |
//* Infinite Scroll | |
wp_enqueue_script( 'infinite-scroll', get_stylesheet_directory_uri().'/js/jquery.infinitescroll.min.js' , array('jquery'), '1.0', true ); | |
wp_enqueue_script( 'infinite-scroll-init', get_stylesheet_directory_uri().'/js/infinitescroll-init.js' , array('jquery'), '1.0', true ); | |
} | |
} | |
add_action( 'wp_enqueue_scripts', 'sk_masonry_script' ); | |
//* Add custom body class to the head | |
add_filter( 'body_class', 'sk_body_class' ); | |
function sk_body_class( $classes ) { | |
if (is_home()||is_archive()) | |
$classes[] = 'masonry-page'; | |
return $classes; | |
} | |
//* Display Post thumbnail, Post title, Post content/excerpt, Post info and Post meta in masonry brick | |
add_action('genesis_meta','sk_masonry_layout'); | |
function sk_masonry_layout() { | |
if (is_home()||is_archive()) { | |
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' ); | |
remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); | |
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); | |
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 ); | |
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 ); | |
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 ); | |
remove_action( 'genesis_entry_content', 'genesis_do_post_content' ); | |
remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); | |
add_action( 'genesis_entry_content', 'sk_masonry_block_post_image', 8 ) ; | |
add_action( 'genesis_entry_content', 'sk_masonry_title_content', 9 ); | |
add_action( 'genesis_entry_footer', 'sk_masonry_entry_footer' ); | |
remove_action( 'genesis_before_loop', 'genesis_do_breadcrumbs' ); | |
add_action( 'genesis_before_content', 'genesis_do_breadcrumbs' ); | |
remove_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 ); | |
add_action( 'genesis_before_content', 'genesis_do_taxonomy_title_description', 15 ); | |
remove_action( 'genesis_before_loop', 'genesis_do_author_title_description', 15 ); | |
add_action( 'genesis_before_content', 'genesis_do_author_title_description', 15 ); | |
remove_action( 'genesis_before_loop', 'genesis_do_author_box_archive', 15 ); | |
add_action( 'genesis_before_content', 'genesis_do_author_box_archive', 15 ); | |
remove_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description' ); | |
add_action( 'genesis_before_content', 'genesis_do_cpt_archive_title_description' ); | |
remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' ); | |
add_action( 'genesis_after_content', 'genesis_posts_nav' ); | |
} | |
} | |
//* Helper function to display Post title and Post content/excerpt wrapped in a custom div | |
function sk_masonry_title_content() { | |
echo '<div class="title-content">'; | |
genesis_do_post_title(); | |
genesis_do_post_content(); | |
echo '</div>'; | |
} | |
//* Helper function to display Post info and Post meta | |
function sk_masonry_entry_footer() { | |
genesis_post_info(); | |
genesis_post_meta(); | |
} | |
//* Set the second parameter to width of your masonry brick (.home .entry, .archive .entry) | |
add_image_size( 'masonry-brick-image', 255, 0, TRUE ); | |
//* Helper function to display featured image | |
//* Source: http://surefirewebservices.com/development/genesis-framework/using-the-genesis-featured-image | |
function sk_masonry_block_post_image() { | |
$img = genesis_get_image( array( 'format' => 'html', 'size' => 'masonry-brick-image', 'attr' => array( 'class' => 'post-image' ) ) ); | |
printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), $img ); | |
} | |
//* Add more link when using excerpts | |
function sk_excerpt_more($more) { | |
return '<a class="more-link" href="'. get_permalink() . '"> [Continue Reading]</a>'; | |
} | |
add_filter('excerpt_more', 'sk_excerpt_more'); | |
//* Modify the length of post excerpts | |
add_filter( 'excerpt_length', 'sk_excerpt_length' ); | |
function sk_excerpt_length( $length ) { | |
return 10; // pull first 10 words | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment