How to Organize and Sort Gallery of Images

I'm working on a website for an artist. He has many images that he would like a user to be able to sort and filter by custom taxonomy. In addition, he would like a user to be able to navigate through a hierarchical gallery with folders (that display a thumbnail) for each level of the hierarchy.

I started by creating a custom post type for "Artwork". I then created several custom taxonomies attached to this CPT. Each "Artwork" cpt has has a featured image and custom taxonomy terms. The archive is working well using these terms.

As far as the gallery, I'm not sure how to go about it. I'm currently accomplishing it with the NextGen gallery but then I can't sort the images by the custom taxonomies unless the client also uploads them to the CPT with the custom taxonomy terms which seems redundant to me.

Here is what the client sent along as a guide: Website Organization

Any suggestions?

Topic plugin-nextgen-gallery gallery custom-post-types Wordpress

Category Web


Finally gave in and used a plugin called Categories Images. Worked like a charm. I still have no clue why my code wasn't work being that I was able to use $child->term_id without problem as term for the plugin to get the correct image. Hopefully in the future, WordPress will support category images out of the box. At least I learned quite a bit about terms!


NextGen gallery isn't built on top of custom post types, so you won't be able to easily link your custom Artwork taxonomies with NextGen. Your best bet is to create archive template files in your theme that can display the artwork like NextGen would. The nested approach you mentioned could be accomplished using hierarchical taxonomies.

For example, you might create an archive-album.php file in your theme with PHP like the following:

<?php
// get children of this taxonomy term so we print out folders for them
$this_term = get_queried_object();
$children = get_term_children( $this_term->term_id , 'album' );
foreach ( $children as $child_term ) {
    $child_term = get_term( $child_term , 'album' );

    if ( ! $child_term->count ) continue; // skip terms with no posts in them

    // get one random post in this child term
    $random_term_post = get_posts( array(
        'posts_per_page'    => 1, // only one post
        'orderby'           => 'rand', // selected randomly
        'tax_query'         => array(
            array(
                'taxonomy'  => 'album', // from this child album
                'terms'     => $child_term->term_id
            )
        )
    ) );

    echo '<a href="' . get_term_link( $child_term ) . '">';
    echo get_the_post_thumbnail( $random_term_post[0] ); // show the random post's thumbnail
    echo $child_term->name;
    echo '</a>';
}

// now print out all Artwork in this particular term
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <!-- print out Artwork here -->
<?php endwhile; else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.