• roadtrip

    (@roadtrip)


    I have the following set up:

    2 custom post types: galleries and artists;
    1 taxonomy: gallery-names
    3 terms of the above taxonomy: a, b, and c

    gallery-names is attached to both galleries and artists, because I want whatever gallery term is called to just call the artists from that term.

    My single-galleries.php is set up where the original loop is the single gallery, and nested inside of it is a wp-query for artists. I also have a speakers nav list dynamically populating the sidebar with anchor links. It works nicely, but when gallery a, b or c is displayed, it shows ALL the artists not just the artist attached to their respective gallery. What I would like to happen is when gallery ‘a’ is displayed, only artists ‘a’ will show, when gallery ‘b’ is displayed, only artists ‘b’ show, etc.

    I haven’t created separate taxonomy templates for these. Should I make separate ones for each gallery i.e. single-galleries-gallery-names-a.php, single-galleries-gallery-names-b.php, single-galleries-gallery-names-c.php? And if so, what would the query loop look like?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter roadtrip

    (@roadtrip)

    I tried to call different sidebar templates with conditional statements, but it’s not working and I’m not sure this is the correct syntax:

    <?php if ( has_term( 'a', 'gallery-names' ) ) {
    
    					    echo get_sidebar('artists-a');
    
    					} elseif ( has_term( 'b', 'gallery-names' ) ) {
    
    					    echo get_sidebar('artists-b');
    
    					} else ( has_term( 'c', 'gallery-names' ) ) {
    
    					    echo get_sidebar('artists-c');
    					}
    
    					?>
    					<?php endif; ?>
      					<?php wp_reset_postdata(); ?>
    Thread Starter roadtrip

    (@roadtrip)

    Update: I did find a solution that I would like to share.

    I created 3 templates: taxonomy-gallerynames-A.php, taxonomy-gallerynames-B.php, and taxonomy-gallerynames-C.php. In each template was basically all the contents from single-galleries.php, but with queries for the different terms (gallery names) in each.

    Then, I found this magical code to put into the archive-galleries.php page, to call the term templates:

    <?php the_terms( $post->ID, 'gallerynames', ' ', ', ', ' ' ); ?>

    Once I popped it into my archive template, I realized what it does. It displays a link that calls my taxonomy-gallerynames-term.php templates! Yay all was right with the world! So I replaced the permalink code, which you would normally use to link to your custom post, and that’s how I got it to work.

    Question, though: Do permalinks not work with taxonomies?

    And further question: How can I make the above code display something other than the TITLE as a link? Because I want the link to say, “MORE DETAILS”. Seems like it would be so simple but I can’t find the answer.

    Tried adding a description on each called ‘More Details’ then modified the code:

    <?php the_terms( $term->description, gallerynames', ' ', ', ', ' ' ); ?>

    but it doesn’t work.

    Although this solution works like a charm, I’m still left wondering if there could be a step I could save by making only ONE taxonomy.gallerynames.php template and calling each gallery name (term) with a conditional statement. For this project I only have 3 gallery names, but what if I had 30? Would I have to create 30 new templates for each?

    Anyway, if anyone could shed light on this, that would be swell. ANd I hope my solution helps anyone out there who is as desperate for a solution as I was!

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query of custom post type to call post with conditional term’ is closed to new replies.