I am, admittedly, a little new to PHP, and I'm trying to get a handle on loops. I'm working on an archive page for a comic website. These comics are broken up into Books, and further broken up into Chapters. I created a custom taxonomy called "Books" and created terms called chapters that have slugs reflecting which book they belong to, such as book-1-chapter-1 (and then there's also a book-2-chapter-1).
I would like to show the title of the chapter, which is the name of the term, but I'm struggling with that. I would like to show the name of the taxonomy term being called, and then loop links to any posts under that. The code is below. My loop works as it's supposed to, but I haven't had luck calling the title. I'd also like the title to not show at all if there are no posts in that category.
<h2>Book 01</h2> <?php $args = array( 'post_type' => 'comic', 'book' => 'book-1-chapter-1', 'order' => 'asc' ); $the_query = new WP_Query( $args ); ?> <h3><!-- Looking to add custom taxonomy term title here --></h3> <ul class="archive-list">– <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <li><a href="<?php the_permalink() ?>"><?php the_title();?></a> –</li> <?php endwhile; endif; ?> </ul>
Any help would be appreciated. If there's a better way to do this I'm open to that too. Like I said, I'm still learning!