srikat

Untitled

Feb 15th, 2017
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. /**
  2. * Default to first attached image
  3. *
  4. * @author Bill Erickson
  5. * @link http://www.billerickson.net/code/default-to-most-recent-image
  6. *
  7. * @param array $defaults
  8. * @param array $args
  9. * @return array $defaults
  10. */
  11. function ea_default_to_most_recent_image( $defaults, $args ) {
  12. $image_ids = array_keys(
  13. get_children(
  14. array(
  15. 'post_parent' => isset( $args['post_id'] ) ? $args['post_id'] : get_the_ID(),
  16. 'post_type' => 'attachment',
  17. 'post_mime_type' => 'image',
  18. 'orderby' => 'menu_order',
  19. 'order' => 'ASC',
  20. )
  21. )
  22. );
  23.  
  24. $defaults['num'] = key( array_slice( $image_ids, 0, 1 ) );
  25. return $defaults;
  26. }
  27. add_filter( 'genesis_get_image_default_args', 'ea_default_to_most_recent_image', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment