Created
November 9, 2017 07:10
-
-
Save raewrites/4e5db4402d76514b956fb856bd9de9b2 to your computer and use it in GitHub Desktop.
Use First Post Image
This file contains 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
//function to call first uploaded image in functions file | |
function main_image() { | |
$files = get_children('post_parent='.get_the_ID().'&post_type=attachment | |
&post_mime_type=image&order=desc'); | |
if($files) : | |
$keys = array_reverse(array_keys($files)); | |
$j=0; | |
$num = $keys[$j]; | |
$image=wp_get_attachment_image($num, 'large', true); | |
$imagepieces = explode('"', $image); | |
$imagepath = $imagepieces[1]; | |
$main=wp_get_attachment_url($num); | |
$template=get_template_directory(); | |
$the_title=get_the_title(); | |
print "<img class="frame" src="$main" alt="$the_title" />"; | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment