How do I edit archive.php to sort posts by category?
-
Here’s the deal, I’ve made a copy of Virtue’s archive.php (called archive-supplier_post.php) to display my custom post type Supplier. I used GenerateWP’s custom post type generator to get the code for functions.php.
The ultimate goal is this: Suppliers (CPT) within a specific category should be put inside a div for suppliers of said category. Water suppliers should all be put in the same div called “Water”, and so on.
This is what my archive looks like so far:
<?php global $virtue; ?> <div id="pageheader" class="titleclass"> <div class="container"> <?php get_template_part('templates/page', 'header'); ?> </div><!--container--> </div><!--titleclass--> <div id="content" class="container"> <div class="row"> <div class="main <?php echo esc_attr(kadence_main_class()); ?> supplierlist" role="main"> <?php if( have_posts() ) : while (have_posts() ) : the_post(); ?> <?php get_template_part('content', 'suppliers'); ?> <?php if ( in_category( '32' ) ) : ?> <div class="post-water"> <?php elseif ( in_category( '33' ) ) : ?> <div class="post-sewer"> <?php elseif ( in_category( '34' ) ) : ?> <div class="post-pump"> <?php else : ?> <div class="post"> <?php endif; ?> <?php endwhile; else :?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?> <?php if ($wp_query->max_num_pages > 1) : virtue_wp_pagenav(); endif; ?> </div><!-- /.main -->
This creates a div class=”post-category” for every post, which is not what I want. I need the posts to be inserted into a div that holds all posts of the same category.
Anyone got any ideas?
Thanks,
JT
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How do I edit archive.php to sort posts by category?’ is closed to new replies.