Last active
August 29, 2015 13:56
-
-
Save srikat/9034625 to your computer and use it in GitHub Desktop.
Posts in columns with oEmbed support for excerpts on homepage in Dynamik. http://sridharkatakam.com/posts-columns-oembed-support-excerpts-homepage-dynamik/
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 | |
/** | |
* To display Posts on site's front page in a 2-column responsive grid. | |
* URL: http://sridharkatakam.com/posts-columns-oembed-support-excerpts-homepage-dynamik/ | |
*/ | |
// Force full width content | |
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' ); | |
// Force excerpts regardless of theme's Content Archive settings | |
add_filter( 'genesis_pre_get_option_content_archive', 'sk_force_excerpts' ); | |
function sk_force_excerpts() { | |
return 'excerpts'; | |
} | |
// Remove featured images if set to appear in Content Archive settings (since it is not possible to select a custom size only for homepage) | |
add_filter( 'genesis_pre_get_option_content_archive_thumbnail', 'sk_show_post_image' ); | |
function sk_show_post_image() { | |
return '0'; | |
} | |
// Show featured image with a custom image size | |
add_action( 'genesis_entry_content', 'custom_post_image', 9 ); | |
function custom_post_image() { | |
genesis_image( array( 'size' => 'custom-thumb-1' ) ); | |
} | |
// Move featured image from below post info to above post title | |
// remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 ); | |
// add_action( 'genesis_entry_header', 'genesis_do_post_image', 8 ); | |
// Remove entry meta | |
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 ); | |
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 ); | |
remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); | |
// Add Post Class Filter to apply 'first' class to first (left) post in each row | |
add_filter('post_class', 'sk_post_class'); | |
function sk_post_class($classes) { | |
global $loop_counter; | |
$classes[] = 'one-half'; | |
if (($loop_counter + 2) % 2 == 0) { | |
$classes[] .= 'first'; | |
} | |
$loop_counter++; | |
return $classes; | |
} | |
// Custom excerpt showing first oEmbed | |
remove_filter('get_the_excerpt', 'wp_trim_excerpt'); | |
add_filter('get_the_excerpt', 'custom_wp_trim_excerpt'); | |
function custom_wp_trim_excerpt($text) { | |
$raw_excerpt = $text; | |
if ( '' == $text ) { | |
$text = get_the_content(''); // Original Content | |
$text = strip_shortcodes($text); // Minus Shortcodes | |
$text = apply_filters('the_content', $text); // Filters | |
$text = str_replace(']]>', ']]>', $text); // Replace | |
$excerpt_length = apply_filters('excerpt_length', 55); // Length | |
$excerpt_more = apply_filters('excerpt_more', ' ' . '<a class="more-link" href="'. get_permalink() .'">Read more »</a>'); | |
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); | |
// Add first oEmbed to excerpt | |
$postcustom = get_post_custom_keys(); | |
if ($postcustom){ | |
$i = 1; | |
foreach ($postcustom as $key){ | |
if (strpos($key,'oembed')){ | |
foreach (get_post_custom_values($key) as $embedded_content){ | |
if ($i == 1){ | |
$text = $text.$embedded_content; | |
} | |
$i++; | |
} | |
} | |
} | |
} | |
} | |
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); | |
} | |
genesis(); |
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
//* Enqueue FitVids | |
add_action( 'wp_enqueue_scripts', 'enqueue_fitvids' ); | |
function enqueue_fitvids() { | |
wp_enqueue_script( 'fitvids', get_bloginfo('url') . '/wp-content/js/jquery.fitvids.js', array( 'jquery' ), '', true ); | |
wp_enqueue_script( 'fitvids-init', get_bloginfo('url') . '/wp-content/js/jquery.fitvids.init.js', array( 'fitvids' ), '1.0.0', true ); | |
} | |
//* Set number of posts per page for homepage | |
add_action( 'pre_get_posts', 'sk_posts_per_page_home' ); | |
function sk_posts_per_page_home( $query ) { | |
if( $query->is_main_query() && !is_admin() && is_home() ) { | |
$query->set( 'posts_per_page', '4' ); | |
} | |
} |
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 .content .entry.one-half { | |
margin-left: 2.5641%; | |
} | |
.home .content .entry.one-half.first { | |
margin-left: 0; | |
} | |
.home .entry iframe { | |
margin-top: 20px; | |
} | |
.home .one-half { | |
width: 48.7179%; | |
} | |
.home .content .override { | |
padding-left: 0; | |
padding-right: 0; | |
} | |
@media only screen and (max-width: 768px) { | |
.home .one-half { | |
width: 100%; | |
} | |
.home .content .entry.one-half { | |
margin-left: 0; | |
} | |
.home .content .entry { | |
margin-bottom: 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment