Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Default to first attached image
- *
- * @author Bill Erickson
- * @link http://www.billerickson.net/code/default-to-most-recent-image
- *
- * @param array $defaults
- * @param array $args
- * @return array $defaults
- */
- function ea_default_to_most_recent_image( $defaults, $args ) {
- $image_ids = array_keys(
- get_children(
- array(
- 'post_parent' => isset( $args['post_id'] ) ? $args['post_id'] : get_the_ID(),
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image',
- 'orderby' => 'menu_order',
- 'order' => 'ASC',
- )
- )
- );
- $defaults['num'] = key( array_slice( $image_ids, 0, 1 ) );
- return $defaults;
- }
- add_filter( 'genesis_get_image_default_args', 'ea_default_to_most_recent_image', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment