Created
June 8, 2016 18:45
-
-
Save ChristopherNeetz/7867b401a5e2fb1961de0c095d1d06f7 to your computer and use it in GitHub Desktop.
Genesis page template with full blog post and additional posts with excerpts
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 | |
//* Template Name: Featured Blog with excerpts | |
// Genesis page template with full blog post and additional posts with excerpts | |
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 ); | |
function custom_excerpt_length( $length ) { | |
return 50; | |
} | |
add_action('genesis_loop', 'load_latestpost'); | |
function load_latestpost() { | |
$displayed_full_content = false; | |
$posts = new WP_Query( 'post_type=post&posts_per_page=5' ); | |
while ( $posts->have_posts() ) { | |
$posts->the_post(); | |
// For the first post, display the full content. | |
if ( ! $displayed_full_content ) { | |
// From Genesis Loops | |
printf( '<article %s>', genesis_attr( 'entry' ) ); | |
do_action( 'genesis_entry_header' ); | |
do_action( 'genesis_before_entry_content' ); | |
printf( '<div %s>', genesis_attr( 'entry-content' ) ); | |
do_action( 'genesis_entry_content' ); | |
echo '</div>'; | |
do_action( 'genesis_after_entry_content' ); | |
do_action( 'genesis_entry_footer' ); | |
echo '</article>'; | |
$displayed_full_content = true; | |
} else { | |
// From Genesis Loops with excerpt | |
printf( '<article %s>', genesis_attr( 'entry' ) ); | |
do_action( 'genesis_entry_header' ); | |
do_action( 'genesis_before_entry_content' ); | |
printf( '<div %s>', genesis_attr( 'entry-content' ) ); | |
the_excerpt(); | |
echo '</div>'; | |
do_action( 'genesis_after_entry_content' ); | |
do_action( 'genesis_entry_footer' ); | |
echo '</article>'; | |
} | |
} | |
} | |
genesis(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment