Created
September 29, 2013 06:45
-
-
Save srikat/6749944 to your computer and use it in GitHub Desktop.
Adding a Featured area above posts when using Masonry in Genesis. http://sridharkatakam.com/adding-featured-area-posts-using-masonry-genesis/
This file contains hidden or 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 | |
//* Start the engine | |
include_once( get_template_directory() . '/lib/init.php' ); | |
//* Child theme (do not remove) | |
define( 'CHILD_THEME_NAME', 'Genesis Sample Theme' ); | |
define( 'CHILD_THEME_URL', 'http://www.studiopress.com/' ); | |
define( 'CHILD_THEME_VERSION', '2.0.1' ); | |
//* Enqueue Lato Google font | |
add_action( 'wp_enqueue_scripts', 'genesis_sample_google_fonts' ); | |
function genesis_sample_google_fonts() { | |
wp_enqueue_style( 'google-font-lato', '//fonts.googleapis.com/css?family=Lato:300,700', array(), CHILD_THEME_VERSION ); | |
} | |
//* Add HTML5 markup structure | |
add_theme_support( 'html5' ); | |
//* Add viewport meta tag for mobile browsers | |
add_theme_support( 'genesis-responsive-viewport' ); | |
//* Add support for custom background | |
add_theme_support( 'custom-background' ); | |
//* Add support for 3-column footer widgets | |
add_theme_support( 'genesis-footer-widgets', 3 ); | |
// ================================================================= | |
// = 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' ); | |
add_action( 'genesis_loop', 'sk_add_home_featured', 9 ); | |
add_action( 'genesis_loop', 'sk_article_container_closing_div' ); | |
} | |
} | |
//* 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 | |
} | |
/** Register widget area */ | |
genesis_register_sidebar( array( | |
'id' => 'home-featured', | |
'name' => __( 'Home Featured', 'genesis-sample' ), | |
'description' => __( 'This is the home featured section.', 'genesis-sample' ) | |
) ); | |
function sk_add_home_featured() { | |
genesis_widget_area( 'home-featured', array( | |
'before'=> '<div class="home-featured widget-area">', | |
'after' => '</div><div class="article-container">', | |
) ); | |
} | |
function sk_article_container_closing_div() { | |
echo "</div>"; | |
} | |
function load_custom_scripts() { | |
wp_enqueue_script( 'my-jquery-additions', get_bloginfo( 'stylesheet_directory' ) . '/js/myjquery.js', array( 'jquery' ), '1.0.0' ); | |
} | |
add_action( 'wp_enqueue_scripts', 'load_custom_scripts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment