Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter anthony_sup

    (@anthony_sup)

    sorry for my english i’m a f*** frenchy ??

    This question is exactly what I’m here looking for, too! I love how easy it is to allow my users to add multiple pictures to a post, but I want to output the gallery pictures in a very specific way, so I’m looking for the tags necessary to do that.

    Thanks

    Je met d’abord la réponse en Anglais mais j’ai réécris en Fran?ais après si jamais ??

    ——————-

    Found easily a solution in the plugin files, I wrote a function to help you. Add it to your functions.php file

    ————————————————

    J’ai trouvé la solution facilement dans les fichiers du plugin. Il suffit d’ajouter la fonction ci-dessous dans le fichier functions.php

    function get_images_from_wpsimplegalleries($post_id) {
        $images = array();
        $gallery = get_post_meta($post_id, 'wpsimplegallery_gallery', true);
        $gallery = (is_string($gallery)) ? @unserialize($gallery) : $gallery;
        foreach ($gallery AS $img_id) {
            $images[] = wp_get_attachment_url($img_id);
        }
        return $images;
    }

    Usage / Utilisation :
    $gallery = get_images_from_wpsimplegalleries(get_the_id());

    Petite mise à jour du code pour éviter les erreurs et pouvoir choisir son format d’image :
    Small update to avoid errors and be able to choose the image format :

    function get_images_from_wpsimplegalleries($post_id) {
        $images = array();
        $gallery = get_post_meta($post_id, 'wpsimplegallery_gallery', true);
        $gallery = (is_string($gallery)) ? @unserialize($gallery) : $gallery;
        if (!empty($gallery)) {
            foreach ($gallery AS $img_id) {
                $img = wp_get_attachment_image_src($img_id, 'projects-gallery');
                $images[] = $img[0];
            }
        }
        return $images;
    }

    Maintenant, je vérifie que la galerie existe et j’ai utilisé wp_get_attachment_image_src() à la place de wp_get_attachment_url() pour pouvoir choisir le format de l’image

    Now I check if the gallery is not empty and I used wp_get_attachment_image_src() instead of wp_get_attachment_url() to be able to choose image format

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get Url of images’ is closed to new replies.