Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to use my category.php file to display all posts of a certain custom post type (say "Company") with a given category. However, when I try to use it by navigating to domain.com/category/company/category1, which is the link automatically generated by wp_list_categories(), no posts appear.

The code I'm using is:

<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'type-company', get_post_format() ); ?>
<?php endwhile; ?>

What am I doing wrong?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

I figured it out! For anyone having the same problem, I solved it by adding

$cat_id = get_query_var('cat'); 
query_posts("post_type=company&cat=$cat_id");

right in front of the loop. Anyone having the same problem would probably also benefit from looking at this, too.

share|improve this answer

Are you using the core category taxonomy, by applying it to your Custom Post Type, or have you defined a custom taxonomy?

If you're using a custom taxonomy, you need to use the template file taxonomy-{taxonomy}.php, or taxonomy-{taxonomy}-{term}.php.

But really, using category.php or taxonomy.php really may not be what you want to do. Have you tried using archive-{post-type}.php, for displaying the archive index list of posts from your Custom Post Type?

You also have an issue with this:

<?php get_template_part( 'type-company', get_post_format() ); ?>

The Post Format taxonomy only applies to the Post post-type; not to any, arbitrary post-type. Again: did you custom-apply the Post Format taxonomy to your Custom Post Type?

EDIT

Note: you may need to modify the Loop query in category.php and/or tag.php, in order to display your CPTs.

share|improve this answer
    
I'm using the core category taxonomy for my Custom Post Type; the blog itself does not use categories. I could create an archive-{post-type}.php document, but I need to only display the posts in a given category, so category.php seems like a natural choice. –  daysrunaway Jul 10 '11 at 3:16
    
I've fixed the issue with get_post_format(): I'm now using get_template_part( 'content-company' ); and I've also tried type-company and single-company—none work. –  daysrunaway Jul 10 '11 at 3:17
    
Do you have template-part files named content-company.php, type-company.php, or single-company.php? –  Chip Bennett Jul 10 '11 at 3:23
    
Yes, I do. Do I need to store them somewhere in particular? They're in the root of my theme folder. –  daysrunaway Jul 10 '11 at 3:30
    
Alternatively, do I need to use a special variant of the loop, or add a query before it? –  daysrunaway Jul 10 '11 at 3:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.