Jump to content

Display posts by category


IQC

Recommended Posts

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;?>

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.