jeudi 7 juillet 2016

How to use size class in Advanced Custom Fields WP?

I am using Advanced custom fields in my WordPress theme to manage my slider images of Flexslider. I upload the images high quality in the backend, but I only want to show the images with a size of 960px width.

In the documentation is mentioned that the size is stored in the [sizes] array.

https://www.advancedcustomfields.com/resources/gallery/

Does anyone know if the custom sizes that are created in the functions.php file will exist also in the stored array?

And my second question is to get access of a specific size class, should you still use [url] to get the image url or is it automatically stored in the array of sizes?

So is this the correct markup:

<?php foreach( $images as $image ): ?>
    <li>
        <img src="<?php echo $image['url']['sizes']['slider-image']; ?>" alt="<?php echo $image['alt']; ?>">
    </li>
<?php endforeach; ?>

or:

<?php foreach( $images as $image ): ?>
    <li>
        <img src="<?php echo $image['slider-image']; ?>" alt="<?php echo $image['alt']; ?>">
    </li>
<?php endforeach; ?>

Aucun commentaire:

Enregistrer un commentaire