Created
May 10, 2017 23:25
-
-
Save ajvillegas/8165ee358273978e3471ffcff8f1450e to your computer and use it in GitHub Desktop.
Illustrates how to display attachments using data extracted from wp_prepare_attachment_for_js().
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 | |
/** | |
* Illustrates how to display a basic list of attachments when using data extracted | |
* from the wp_prepare_attachment_for_js() array. | |
* | |
* @author Alexis J. Villegas <[email protected]> | |
* @link https://developer.wordpress.org/reference/functions/wp_prepare_attachment_for_js/ | |
*/ | |
// Attachment IDs | |
$images = array( '3508', '2519', '2461', '2801', ); | |
// Display attachments | |
if ( $images ) { ?> | |
<div class="attachment-images"> <?php | |
foreach( $images as $image ) { | |
// Get attachment details | |
$attachment = wp_prepare_attachment_for_js( $image ); ?> | |
<div> | |
<a href="<?php echo $attachment['link']; ?>"> | |
<img src="<?php echo $attachment['sizes']['medium']['url']; ?>" alt="<?php echo $attachment['alt']; ?>" /> | |
</a> | |
<p><?php echo $attachment['caption']; ?></p> | |
</div> <?php | |
} ?> | |
</div> <?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment