I have an archive-custom_post_name.php that outputs content from a custom post type structured like so:
<?php get_header(); ?>
<?php if ( have_posts() ) : ?>
<?php $post_type = $wp_query->get_queried_object(); ?>
// HTML Section header here
<?php get_template_part('loop', 'masonry'); ?>
<?php endif ?>
<?php get_footer(); ?>
Which leads to a template part file containing a loop:
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'masonry' ) ?>
<?php endwhile; ?>
Which leads to a template part which defines the HTML for each piece of content in the loop.
What I need is to amend the file archive-custom_post_name.php so that it iterates through all categories used by posts of the custom post type, outputting an HTML section header for each one, and all posts bearing each category below.
So where there were three categories, each with three posts
// HTML Section header for cat one
// Post with cat one
// Post with cat one
// Post with cat one
// HTML Section header for cat two
// Post with cat two
// Post with cat two
// Post with cat two
// HTML Section header for cat three
// Post with cat three
// Post with cat three
// Post with cat three
As I mention, my preferred approach is to amend the top level file archive-custom_post_name.php rather than lower down the template hierarchy I have if possible.
Any help appreciated, I'm rather stumped!