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?

2 Answers 2


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:

// 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(
                '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; ?>
  • Thank you for your input John. That is pretty much what I've done so far except I used the taxonomy "album". I have an archive-album.php file that controls what is displayed on each level of the hierarchy using a conditional statement. Terms with children show a list of the children terms as "folders" and terms with no children show the images associated with that term. You can view my progress at staging.designs4theweb.com/album/paintings/2015. I'm just at a loss as to how to get an image to show for each "folder". Commented Dec 8, 2015 at 2:30
  • Here is my code: gist.github.com/mikeoberdick/5f69aa0586d45e3281e0 Commented Dec 8, 2015 at 2:42
  • Updated the above code with how to get images for each folder. Commented Dec 10, 2015 at 2:20
  • Thank you for your input @John, I really appreciate it and have learned quite a bit during this project. I used your code and things are great, however, it seems like the newest image is showing up as the one for the folder each time. Also, if I post an image in the "portrait" album which is a child of 2015, it is showing up as the folder image for 2014 and 2013 as well. See here Commented Dec 10, 2015 at 4:04
  • Thanks @John. Can anyone help? I know I am very close but each folder is showing the same image. So 2015, 2014, and 2013 are all showing the same artwork thumbnail. It seems we are one level off. Here is my code. Commented Dec 12, 2015 at 12:49

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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