[resolved] Gallery feature in 2.5 - get array of images (2 posts)

  1. AshSplash
    Posted 6 years ago #

    Hi everyone,

    I'm loving the WP gallery feature that was added in v2.5 however I have a problem that I do hope will be easy for someone to answer.

    I have a page where I have a number of images in the gallery, this page also has a custom template. I want to display the images in a very particular way to the end user however can't seem to find a way to override the default gallery HTML.

    What would be perfect would be a PHP array of all the images and their captions etc so that I can manipulate them as the design requires.

    Thanks for your help.

  2. AshSplash
    Posted 6 years ago #

    I've managed to solve this with regex, certainly not the best solutions but does what it needs to.

    For those that need it add the following to your template and manipulate the $images array until you've got the data you need.

    $gallery = do_shortcode('[gallery link="file"]');
    $images = array();
    preg_match_all('|<a.*?href\s*=\s*["](.*?)["].*?>(.*?)</a>|i', $gallery, $images);

Topic Closed

This topic has been closed to new replies.

About this Topic