Created
February 16, 2015 14:07
-
-
Save robincornett/95645ac672907630ec35 to your computer and use it in GitHub Desktop.
snippet to use the term featured image as the post featured image on blog/archive pages, if the post has no featured image of its own. Requires the Display Featured Image for Genesis plugin.
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 | |
// do not include the opening tag! | |
add_action( 'genesis_entry_content', 'rgc_add_term_image_archives' ); | |
function rgc_add_term_image_archives() { | |
if ( ! is_home() && ! is_archive() ) { | |
return; | |
} | |
if ( ! has_post_thumbnail() ) { | |
$taxonomies = get_taxonomies(); | |
$args = array( 'orderby' => 'count', 'order' => 'DESC' ); | |
$terms = wp_get_object_terms( get_the_ID(), $taxonomies, $args ); | |
$image_id = ''; | |
foreach ( $terms as $term ) { | |
$t_id = $term->term_id; | |
$term_meta = get_option( "displayfeaturedimagegenesis_$t_id" ); | |
if ( ! empty( $term_meta['term_image'] ) ) { | |
$image_id = Display_Featured_Image_Genesis_Common::get_image_id( $term_meta['term_image'] ); | |
break; | |
} | |
} | |
if ( ! empty( $image_id ) ) { | |
$image_source = wp_get_attachment_image_src( $image_id, 'medium' ); | |
$image = '<img src="' . esc_url( $image_source[0] ) . '" class="alignright" />'; | |
echo $image; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment