Skip to content

Instantly share code, notes, and snippets.

@About2git
Forked from srikat/functions.php
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save About2git/ee8cb714d74389c9b7e1 to your computer and use it in GitHub Desktop.

Select an option

Save About2git/ee8cb714d74389c9b7e1 to your computer and use it in GitHub Desktop.
Wide Featured images for the latest 3 Posts and thumbnails for the rest in Genesis
//* Add new image size
add_image_size( 'home-featured-image', 680, 0, true );
add_action( 'pre_get_posts', 'sk_set_posts_per_page_home' );
/**
* Change Posts Per Page for Event Archive
*
* @author Bill Erickson
* @link http://www.billerickson.net/customize-the-wordpress-query/
* @param object $query data
*
*/
function sk_set_posts_per_page_home( $query ) {
if( $query->is_main_query() && !is_admin() && is_home( ) ) {
$query->set( 'posts_per_page', '6' );
}
}
<?php
//* Remove Featured image (if set in Theme Settings)
add_filter( 'genesis_pre_get_option_content_archive_thumbnail', 'sk_no_post_image' );
function sk_no_post_image() {
return '0';
}
//* Show Excerpts regardless of Theme Settings
add_filter( 'genesis_pre_get_option_content_archive', 'sk_show_excerpts' );
function sk_show_excerpts() {
return 'excerpts';
}
//* Modify the Excerpt read more link
add_filter('excerpt_more', 'new_excerpt_more');
function new_excerpt_more($more) {
return '... <a class="more-link" href="' . get_permalink() . '">[Continue Reading]</a>';
}
//* Make sure content limit (if set in Theme Settings) doesn't apply
add_filter( 'genesis_pre_get_option_content_archive_limit', 'sk_no_content_limit' );
function sk_no_content_limit() {
return '0';
}
//* Display centered wide featured image for top three Posts and left aligned thumbnail for the next three
add_action( 'genesis_entry_content', 'sk_show_featured_image', 9 );
function sk_show_featured_image() {
if ( ! has_post_thumbnail() ) {
return;
}
global $wp_query;
if( ( $wp_query->current_post <= 2 ) ) {
$image_args = array(
'size' => 'home-featured-image',
'attr' => array(
'class' => 'aligncenter',
),
);
} else {
$image_args = array(
'size' => 'thumbnail',
'attr' => array(
'class' => 'alignleft',
),
);
}
$image = genesis_get_image( $image_args );
echo '<div class="home-featured-image"><a href="' . get_permalink() . '">' . $image .'</a></div>';
}
//* 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' );
//* Display custom HTML above the first Post and above fourth Post, only on the front page
add_action( 'genesis_before_entry', 'sk_custom_heading' );
function sk_custom_heading() {
if ( is_paged() ) {
return;
}
global $wp_query;
if( ( $wp_query->current_post == 0 ) ) {
echo '<h4 class="home-posts-section-heading">Latest Posts</h4>';
} elseif( ( $wp_query->current_post == 3 ) ) {
echo '<h4 class="home-posts-section-heading">Previous Posts</h4>';
}
}
genesis();
.home-posts-section-heading {
text-align: center;
text-transform: uppercase;
margin-bottom: 40px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment