Last active
December 16, 2015 00:49
-
-
Save GaryJones/5350636 to your computer and use it in GitHub Desktop.
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 | |
| add_action( 'genesis_before_post', 'dc_blah_feat' ); | |
| /** | |
| * Echo parent page post thumbnail for a page. | |
| */ | |
| function dc_blah_feat () { | |
| if ( is_page() ) | |
| echo prefix_get_page_parent_featured_image(); | |
| } | |
| /** | |
| * Get featured image of current page's parent page. | |
| * | |
| * @return string Post thumbnail markup, or empty string if not currently on a page. | |
| */ | |
| function prefix_get_page_parent_featured_image() { | |
| if ( ! is_page() ) | |
| return ''; | |
| $parents = get_post_ancestors( get_the_ID() ); | |
| $id = $parents ? $parents[ count( $parents ) - 1 ] : get_the_ID(); | |
| return get_the_post_thumbnail( $id, 'full' ); | |
| } |
Author
Thanks again, Gary. Just used this in a slightly different way. Does the conditional check prevent the need for the global $post?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a couple of extra lines of code longer than the original, but you get:
global $post.