WordPress.org

Ready to get started?Download WordPress

Forums

Displaying only posts in selected category (2 posts)

  1. bluedrag
    Member
    Posted 1 year ago #

    I have a working category page, which displays a featured image and post title inside a box, and goes to the full post when clicked on. The only problem is each seperate category displays all posts (no matter the category). How would I code this to only dislay posts inside the selected category?

    My code is below.

    <?php
    /**
     * The template for displaying Category Archive pages.
     *
     * @package Toolbox
     * @since Toolbox 0.1
     */
    
    get_header(); ?>
    
    		<section id="primary">
    			<div id="content" class="product_gallery" role="main">
    
    			<h1 class="cat_title"><?php single_cat_title(); ?></h1>
    
    				<?php /* Start the Loop */ ?>
    				<?php while ( have_posts() ) : the_post(); ?>
    
    		<ul>
    			<?php
    			// we add this, to show all posts in our
    			// Glossary sorted alphabetically
    
    			$args = array( 'posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC', 'category'  => 'Piccolos' );
    
    			$glossaryposts = get_posts( $args ); 
    
    			foreach( $glossaryposts as $post ) :	setup_postdata($post);
    			 ?>
    				<div class="product_thumbnail">
    				<a href="<?php the_permalink(); ?>">
    					<?php the_post_thumbnail('thumbnail', array('class' => 'thumbnail')); ?>
    					<p class="post_caption"><?php the_title(); ?></p>
    				</a>
    				</div>
    			<?php endforeach; ?>
    		</ul>
    
    				<?php endwhile; ?>
    
    			</div><!-- #content -->
    		</section><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
  2. christopherross
    Member
    Posted 1 year ago #

    @bluedrag, in the case of get_posts() the category has to be a category ID, not the word.

    http://codex.wordpress.org/Function_Reference/get_posts

Topic Closed

This topic has been closed to new replies.

About this Topic