Last active
December 3, 2019 07:11
-
-
Save topleague/cb3e28d6a76b696137337559f2691d4d to your computer and use it in GitHub Desktop.
How to Display Featured Image and Overlay Entry Title with Excerpts on Blog Page in 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
//* Add Excerpt support to Pages in Genesis | |
add_post_type_support( 'page', 'excerpt' ); | |
//* Display Page Title and Page Excerpt (as Subtitle) after Header | |
add_action( 'genesis_header', 'blog_archive_remove_page_title'); | |
function blog_archive_remove_page_title () { | |
if (is_home() && get_option('page_for_posts')) { | |
add_action( 'genesis_after_header', 'blog_archive_after_header_content' ); | |
function blog_archive_after_header_content() { | |
// Set $image to URL of featured image. If featured image is not present, set it to post-image.jpg in child theme's images directory. | |
if ( has_post_thumbnail() ) { | |
$img = wp_get_attachment_image_src(get_post_thumbnail_id(get_option('page_for_posts')),'full'); | |
$featured_image = $img[0]; | |
} else { | |
$image = get_stylesheet_directory_uri() . '/images/post-image.jpg'; | |
} ?> | |
<div class="post-hero" style="background-image: linear-gradient(to right, white, transparent), url('<?php echo $img[0]; ?>')"> | |
<div class="wrap"> | |
<?php echo '<h1 itemprop="headline" class="blog-title">' . genesis_do_posts_page_heading() . '</h1>'; ?> | |
<?php echo '<p class="page-excerpt">' . get_the_excerpt() . '</p>'; ?> | |
</div> | |
</div> | |
<?php | |
} | |
} | |
// Remove entry meta from header | |
remove_action( 'genesis_before_loop', 'genesis_do_posts_page_heading' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment