I have a custom post type and I’m trying to display a category page so when you click on a standard link to a category, you will see all of the posts in that category… It seems simple, and I have looked at the WordPress hierarchy, but I can’t figure out which template files I need to create…

I currently have this page pulling through my custom fields: http://ideedev.co.uk/newseed/brand/ NOT looping through custom post types. The code is essentially this:

<?php
/**
 * Template name: Main Category Template
 */
?>

<?php get_header(); the_post(); ?>



<!-- Featured Image ===========================================  -->

<div class="image-test-container">

    <?php if ( has_post_thumbnail() ) {

    // Get the post thumbnail URL
    $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
  } else {

    ?>
    <style type="text/css">.featured-image{
    display:none;
    }</style>
    <?php
  } ?>


    <div id="absolute1111" style=" background: url(<?php echo $feat_image; ?>);">
        <div class="centerd1111">
            <h1><?php the_title(); ?></h1>
        </div>
    </div>  

</div>





<!-- Page Content ===========================================  -->

<div class="container">

    <div class="row clearfix">
    <div class="">

    </div>
    </div>

    <div class="row clearfix">
    <div class="level-two-intro-text">
        <p><?php the_field('intro_text'); ?></p>
    </div>
    <div class="level-two-sub-title block__title">
        <?php the_field('sub_title'); ?>
    </div>
    </div>

</div>





<!-- Areas ===========================================  -->

<div class="container">
    <div class="row clearfix">

        <?php if(get_field('areas')): ?>


                <?php while(has_sub_field('areas')): ?>


                    <div class="single-area-item six columns">
                        <p> <img src="<?php the_sub_field('area_icon'); ?>" style="width:100%;"> <p>
                        <h2> <?php the_sub_field('area_title'); ?> </h2> 
                        <p> <?php the_sub_field('area_info'); ?> <p>
                        <div class="area-button"><a href="<?php the_sub_field('button_target'); ?>" class="btn btn--dark-blue" role="button"><?php the_sub_field('button_text'); ?></a></div>
                    </div>


                <?php endwhile; ?>


        <?php endif; ?>

    </div>
</div>

However, When I click on the Portfolio button under each category, I would like it to display a page of that category…

I could make this work by creating a single template page for each category and looping through and display all posts within a specific category, but that seems like the wrong way – I’m thinking there should be one template to show the category I have just clicked on…

I think I’m getting a little confused to be honest. Thanks for looking 🙂

Read more here: Adding Category Pages – CPT – WordPress


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: