Created
May 26, 2015 23:01
-
-
Save owise1/3950608a75aad9a5591d to your computer and use it in GitHub Desktop.
wordpress functions
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 | |
/** | |
* Useful Wordpress Functions | |
*/ | |
function first_img($id) { | |
$files = get_children('post_parent='.$id.'&post_type=attachment&post_mime_type=image'); | |
if($files) : | |
$keys = array_reverse(array_keys($files)); | |
$j=0; | |
$num = $keys[$j]; | |
$image=wp_get_attachment_image($num, 'large', false); | |
$imagepieces = explode('"', $image); | |
$imagepath = $imagepieces[1]; | |
$thumb=wp_get_attachment_thumb_url($num); | |
return $thumb; | |
endif; | |
} | |
function acf_img($field, $size){ | |
$ret = get_field($field); | |
return $ret ? $ret['sizes'][$size] : false; | |
} | |
function wp_img($postID, $size){ | |
$ret = wp_get_attachment_image_src($postID, $size); | |
return $ret[0]; | |
} | |
function map_method($array, $methodName) { | |
if(!$array) array(); | |
$returnCode = 'return $a->'. $methodName.';'; | |
return(array_map(create_function('$a', $returnCode), $array)); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment