0

How would one go about creating a gallery page which is a gallery of galleries - using a specific photo from the subgallery as a cover for the album?

This is what I have so far.

I have a folder on the backend built using WP Media Folder called master. I want the galleries page to list a thumbnail for each folder inside of master and a name of the gallery the thumbnail belongs to.

Here is what I have.

$galleries = get_terms( 'wpmf-gallery-category', [ 'hide_empty' => 0 ]);

    foreach ( $galleries as $gal )
    {
        if ( $gal->name != 'master' )
        {
        ?>
            <div id="gallery-id-<? $gal->ID ?>" class="cell medium-3 margin-x text-center" style="border: solid black; ">
                    <figure class="cell">
                        <img src="<?= // Get sub-gallery thumbnail ?>" alt="<?= $gal->name?>">
                    </figure>
                    <div class="detail">
                        <span>
                            <?= $gal->name ?>
                        </span>
                    </div>
            </div>
        <?
        }
     }

I guess the question is, how do I access the images by the folder they are in? I don't see how WP Media Folder links to the images. I need to be able to query and get the image srcs from the gallery element id.

  • Not sure how you envision this. You would have a post with several gallery shortcodes in it and you want them to be assembled into one gallery.That doesn't make sense. Or several posts with galleries to be assembled into one page? – cjbj Jun 20 '18 at 16:31
  • @cjbj I restructured my question if you feel like having a look again. – Daniel Foust Jun 20 '18 at 19:59
  • Looks like your question depends on a datastructure generated by a third party plugin which I know nothing about. So I'd post my question on that plugin's forum. If you want to do this with WordPress as it is, you will have to build a shortcode that accesses the posts where the individual galleries are defined. – cjbj Jun 21 '18 at 14:30
1

I created a custom function for this, but if you want the root folder id, you can use the wp cli and use the command wp term list wpmf-gallery-category to show all the gallery folders. Get the term id of the one you want to use as the root and set it to $master_id

/*
   get_root_gallery_id();
   Custom function that returns the id of folder with parent id == 0
*/
$master_id = get_root_gallery_id( 'master' );
$galleries = get_terms( 'wpmf-gallery-category', [ 'hide_empty' => 0 ]);

            // If there is a root folder
            if ( $master_id )
            {
                foreach ( $galleries as $gal )
                {
                    if ( $gal->parent == $master_id )
                    {
                        $args = [
                            'post_type'      => 'attachment',
                            'posts_per_page' => -1,
                            'post_status'    => 'inherit'

                            'tax_query'      => [
                                [
                                    'taxonomy' => 'wpmf-gallery-category',
                                    'terms'    => [ $gal->term_id ],
                                    'field'    => 'term_id'
                                ]
                            ]
                        ];

                        $query = new WP_Query( $args );

                        if ( $query->have_posts() )
                        {
                            while ( $query->have_posts() )
                            {

                                $query->the_post();

                                global $post; // Image as Post Object
                            }
                        }
                    }
                }
            }
0

We use 2 plugins to accomplish this without programming, the bonus being we don't have to worry about updating the code every 3 months...downside is obvious... MLA Library (Media Library Assistant I think is the actual name) and Content Views Pro by PT Guy. I can't remember if the free let's you filter media.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.