carasmo
9/2/2017 - 6:00 PM

Add intro text on blog posts page or a page using the blog template in Genesis

Add intro text on blog posts page or a page using the blog template in Genesis

<?php
//don't add again


add_action( 'edit_form_after_title', 'your_prefix_posts_page_edit_form' );
/**
 * Add Editor Back on Posts Page
 * @thanks https://robincornett.com/posts-page/
 */
 function your_prefix_posts_page_edit_form( $post ) {
	$posts_page = get_option( 'page_for_posts' );
	if ( $posts_page === $post->ID ) :
		add_post_type_support( 'page', 'editor' );
	endif;
}


add_action( 'genesis_before_loop', 'your_prefix_blog_page_or_blog_template_intro_text' );
/**
 * Add Intro Text entered in the page editor on the:
 * - 1st page of Blog posts page (if it's not the front page)
 * - 1st page of Blog Template page (a page using the Genesis blog template)
 *
 * uses `the_content` filter so you can add shortcodes, videos (embeds), etc.,
 *
 * Does not work if you show latest posts on home page 
 * since there is no page to get content from.
 *
 * @thanks and modified: https://robincornett.com/posts-page/
 */
function your_prefix_blog_page_or_blog_template_intro_text() {
	
	if ( is_front_page() ) return; //* exit if front page
	
	global $post;
	$posts_page = get_option( 'page_for_posts' );
	$content    = '';

	if ( is_home() && ! is_paged() ) :

		$content = get_post( $posts_page )->post_content;
		
	endif; // blog page
	
	if ( is_page_template( 'page_blog.php' ) && ! is_paged()  ) :
	
		$content = $post->post_content;
		
	endif; // page blog template
	
	
	if ( $content != '' ) :
		
		$content = apply_filters( 'the_content', $content );
		
		printf( '<div class="blog-intro-content">%s</div>', $content );
	
	endif;	

}