0
votes

My main portfolio page is setup correctly which is displaying ALL the work, the next step I'm having trouble with is displaying work ONLY from a specific category.

Under the custom content types manager I checked "Enable Categories" under Taxonomies which gave me control to add categories to the content type like the URL below.

For example: http://localhost/category/narrative would display all work with the category "Narrative" attached, right now it's displaying all the work since I copy & pasted the code from the work page.

How can I get this category.php template to detect and display the work associated with the category it's loading?

<?php
/**
 * The template for displaying Category Archive pages
 *
 * @package     WordPress
 */

$res = get_posts(array('post_type' => 'work', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => -1));

get_header(); ?>

<section role="main" class="container">

    <div id="da-thumbs" class="row work-list da-thumbs">

        <? foreach($res as $post) : setup_postdata($post) ?>
        <?
            $thumbnail = get_custom_field('thumbnail');
        ?>

        <div class="col four">
            <a href="<?php echo get_permalink(); ?>">
                <img src="<?=$thumbnail?>" />
                <div><span><?php the_title( '<h3>', '</h3>' ); ?></span></div>
            </a>
        </div>

        <? endforeach; ?>


    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <?php the_content(__('(more...)')); ?>
    <?php endwhile; else: ?>
        <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    </div>
</section>

<?php get_footer(); ?>
1

1 Answers

1
votes

Your get_posts is not filtering by category.

Do something like:

$the_category = get_queried_object();
$cat_id = $the_category->term_id;
$res = get_posts(array('category' => $cat_id, 'post_type' => 'work', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => -1));