How to write a template to list all posts with a custom taxonomy term
-
I have created the custom taxonomy Resource Categories. Within that taxonomy I have two categories/terms: blogs and books.
I have already figured out which file to edit: taxonomy.php
But I can’t figure out how to write the template. Here is what I have so far:
<?php get_header(); ?> <section class="content"> <div class="page-title pad group"><h2><?php single_term_title(); ?></h2></div> <div class="pad group"> <?php if ((category_description() != '') && !is_paged()) : ?> <div class="notebox"> <?php echo category_description(); ?> </div> <?php endif; ?> <?php if ( have_posts() ) : ?> <div class="post-list group"> <?php $i = 1; echo '<div class="post-row">'; while ( have_posts() ): the_post(); ?> <?php get_template_part('content'); ?> <?php if($i % 2 == 0) { echo '</div><div class="post-row">'; } $i++; endwhile; echo '</div>'; ?> </div><!--/.post-list--> <?php get_template_part('inc/pagination'); ?> <?php endif; ?> </div><!--/.pad--> </section><!--/.content--> <?php get_sidebar(); ?> <?php get_footer();
What Works:
1. The page is showing up when I go to /resource-categories/books. Good!
2. The title of the category “Books” and the category description shows up. Good!What doesn’t work:
There is no list of the items in the category. It’s just blank. I originally copied this code from the archive.php, which works just fine on Search pages, Author Lists, I think Category Archives is using that template, etc.What’s wrong?! I’m a php n00000000b so I’m having a hard time translating resources on the internet to solving this problem.
- The topic ‘How to write a template to list all posts with a custom taxonomy term’ is closed to new replies.