Hi all.
This seems like a pretty basic function but I can't work it out.
I'm developing a WordPress site and want to list posts (products) by category. I'm using Advanced Custom Fields and have set up the taxonomy of 'category'.
I just want to produce a heading for that category and then list all of the posts with that category assigned.
Please see below functions.php excerpt and section-archive.php excerpt.
Can anyone please help??? Massive good karma if you can.
----------------------- functions.php --------------------------------------
//Assign Category to Products
function taxonomy ()
{
$args = array (
'labels' => array(
'name' => 'Category',
'singular_name' => 'Category',
),
'public' => true,
'hierarchical' => true,
);
register_taxonomy('name', array('products'), $args);
};
add_action('init', 'taxonomy');
?>
------------------------- section-archive.php ------------------------------------------------
<?php if(have_posts()):while(have_posts()): the_post();?>
****** if product category= this
***** Category heading
****** Posts
******* Else
****** if product category= this2
***** Category heading
****** Posts
**** etc
<div class="prod-listing">
<div class="align-top d-flex">
<div class="blog-content">
<h2><?php the_title();?></h2>
<?php the_content();?>
</div>
</div>
</div>
<?php endwhile; else: endif;?>