Created
May 17, 2012 14:05
-
-
Save samuelsimoes/2719135 to your computer and use it in GitHub Desktop.
Pequena função para retornar um array com as imagens anexadas ao post em questão
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
<?php | |
/* Função para pegar as imagens que estão anexadas ao post */ | |
function pegar_post_imagens() { | |
$imagens = array(); | |
$args = array( | |
'post_type' => 'attachment', | |
'numberposts' => -1, | |
'post_status' => null, | |
'post_parent' => $post->ID, | |
); | |
$imagens_anexadas = get_posts($args); | |
if ($imagens_anexadas) { | |
foreach ($imagens_anexadas as $chave => $anexo) { | |
$imagens_src = wp_get_attachment_image_src($anexo->ID, 'full'); | |
$imagens[$chave]['src'] = $imagens_src[0]; | |
$imagens[$chave]['titulo'] = $anexo->post_title; | |
} | |
} else { | |
if(has_post_thumbnail()) { | |
$imagem_destacada_src = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); | |
$imagens['imagem_destacada']['src'] = $imagem_destacada_src[0]; | |
$imagens['imagem_destacada']['titulo'] = get_post(get_post_thumbnail_id())->post_title; | |
} | |
} | |
return $imagens; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment