• Hello all. I’m having some trouble displaying the posts in a custom post type on my portfolio site, and I’m wondering if someone can help.

    Here’s the deal. I have a custom post type called ‘work.’ Within that custom post type, I have a custom taxonomy called ‘project type’ where I have created several categories called photography, video, print design, etc. I set up a template called taxonomy.php which governs mydomain.com/work as well as mydomain.com/project-type/print-design/. The problem is that these pages only display the 5 most recent posts. I need them to display all the posts in the proper category (or in the case of mydomain.com/work, all of the posts in the custom post type regardless of category). How can I modify this code to display all of the posts?

    Here is the code I have used for taxonomy.php:

    <?php
    
    /**
     * Project Type Taxonomy Archive
     */
    
    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    ?>
    
    <h3 style="color:#EEEEEE"><?php echo apply_filters( 'the_title', $term->name ); ?> PROJECTS</h3>
    
    <ul class="thumbnails">
    	<div id="work">
    
    		<?php if ( !empty( $term->description ) ): ?>
    		<div class="archive-description">
    			<?php echo esc_html($term->description); ?>
    		</div>
    		<?php endif; ?>
    
    		<?php if ( have_posts() ): while ( have_posts() ): the_post(); ?>
    
    		<div class="post">
    			<li class="span4">
    				<div class="thumbnail">
    				<a href="<?php the_permalink() ?>"><div class="tint"><?php the_post_thumbnail( 'featured-thumb' ); ?></div></a>
    				<br />
    				<div class="thumbcaption">
    					<a href="<?php the_permalink() ?>"><h3><?php the_title() ?></h3></a>
    					<p>	<?php the_excerpt(); ?></p>
    					<p><i><?php the_terms( $post->ID, 'work_project_type' ,  ' ' ); ?></i></p>
    				</div>
    				</div>
    			</li>
    		</div>
    
    		<?php endwhile; ?>
    
    		<div class="navigation clearfix">
    			<div class="alignleft"><?php next_posts_link('? Previous Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Next Entries ?') ?></div>
    		</div>
    
    		<?php else: ?>
    
    		<h2 class="post-title">No Projects in <?php echo apply_filters( 'the_title', $term->name ); ?></h2>
    		<div class="content clearfix">
    			<div class="entry">
    				<p>It seems there aren't any projects in <strong><?php echo apply_filters( 'the_title', $term->name ); ?></strong> right now. Check back later, I try to add new projects regularly.</p>
    			</div>
    		</div>
    
    		<?php endif; ?>
    	</div>
    	</div>
    </ul>

    Here’s the link to the work page and here’s a link to a category page. Thanks for your help.

Viewing 2 replies - 16 through 17 (of 17 total)
  • <?php query_posts( array ( ‘post_type’ => ‘work’, ‘posts_per_page’ => -1 ) ); ?>. So now the work page is loading correctly, but all of the category pages are loading all the work posts (because I’ve defined the post_type as work in that snippet I added).

    you need a conditionsl,

    <?php
    if(is_category('category-slug')) {?>
    <?php query_posts( array ( 'post_type' => 'work', 'posts_per_page' => -1 ) ); ?>.
    <?php}?>

    Thread Starter mcography

    (@mcography)

    I figured it out with help from this post. Just needed a custom function to override the posts_per_page for the work archive.

    Thanks again for your help, deep.

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Template to Display All Posts in Custom Post Type and Custom Taxonomy’ is closed to new replies.