Last active
November 9, 2016 23:58
-
-
Save javierarcheni/4f950ed8dd26524570deabfce0dd7b54 to your computer and use it in GitHub Desktop.
Mostrar la leyenda de una imagen destacada en WordPress
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 $thumb_id = get_post_thumbnail_id(); | |
if ($thumb_id != 0) : // existe imagen destacada | |
$thumb_url = wp_get_attachment_image_src($thumb_id,'large', true); | |
$thumbnail_details = get_posts(array('p' => $thumb_id, 'post_type' => 'attachment')); | |
$titulo = $thumbnail_details[0]->post_title; | |
$leyenda = $thumbnail_details[0]->post_excerpt; | |
?> | |
<figure> | |
<img class="img-responsive" alt="<?= esc_attr($titulo); ?>" src="<?= esc_url($thumb_url[0]); ?>" /> | |
<?php if (!empty($leyenda)) : ?> | |
<figcaption> | |
<p><?= esc_html($leyenda); ?></p> | |
<figcaption> | |
<?php endif; ?> | |
</figure> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment