Forums

Display Category posts on a page (3 posts)

  1. cynthea
    Member
    Posted 3 years ago #

    I am trying to display posts from a certain category on a page, but I'm having a hard time getting query_posts to listen to me. It keeps displaying posts from every category instead of the one I have specified.

    I also tried using the LIST CATEGORY POSTS plugin and I get the same result. Posts from every category show up, instead of just the one category I have specified.

    Here is the code I am using (when I'm not using the plugin, of course). Any ideas?

    <?php
    /*
    Template Name: Books
    */
    ?>
    
    <?php get_header(); ?>
    
    	<div id="content_box">
    
    		<?php include (TEMPLATEPATH . '/l_sidebar.php'); ?>
    
    		<div id="content" class="pages">
    
    			<h2><?php the_title(); ?></h2>
    			<div class="entry">
    
    			<h3>2009 Winter</h3>
    			<?php query_posts('cat=55'.'&order=ASC'); ?>
    
    			<?php while (have_posts()) : the_post(); ?>
       			<ul>
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
    			</ul>
      			<?php endwhile;?>
    
    			<h3>2009 Spring</h3>
    			<?php query_posts('cat=7'.'&order=ASC'); ?>
    
    			<?php while (have_posts()) : the_post(); ?>
       			<ul>
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
    			</ul>
      			<?php endwhile;?>
    
    			<h3>2009 Summer</h3>
    			<?php query_posts('cat=7'.'&order=ASC'); ?>
    
    			<?php while (have_posts()) : the_post(); ?>
       			<ul>
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
    			</ul>
      			<?php endwhile;?>
    
    			<h3>2009 Fall</h3>
    			<?php query_posts('cat=9'.'&order=ASC'); ?>
    
    			<?php while (have_posts()) : the_post(); ?>
       			<ul>
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
    			</ul>
      			<?php endwhile;?>
    
    			<h3>2010 Winter</h3>
    			<?php query_posts('cat=59'.'&order=ASC'); ?>
    
    			<?php while (have_posts()) : the_post(); ?>
       			<ul>
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
    			</ul>
      			<?php endwhile;?>
    
    			<h3>2010 Spring</h3>
    			<?php query_posts('cat=56'.'&order=ASC'); ?>
    
    			<?php while (have_posts()) : the_post(); ?>
       			<ul>
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
    			</ul>
      			<?php endwhile;?>
    
    			<h3>2010 Summer</h3>
    			<?php query_posts('cat=57'.'&order=ASC'); ?>
    
    			<?php while (have_posts()) : the_post(); ?>
       			<ul>
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
    			</ul>
      			<?php endwhile;?>
    
    			<h3>2010 Fall</h3>
    			<?php query_posts('cat=58'.'&order=ASC'); ?>
    
    			<?php while (have_posts()) : the_post(); ?>
       			<ul>
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
    			</ul>
      			<?php endwhile;?>
    
    </div>
    			<div class="clear rule"></div>
    
    			<div class="clear"></div>	
    
    		</div>
    
    		<?php include (TEMPLATEPATH . '/r_sidebar.php'); ?>
    
    	</div>
    
    <?php get_footer(); ?>
  2. buddha trance
    Member
    Posted 3 years ago #

    I am also using a template page to pull a specific category, it should work with multiple queries as well.

    The statement I use for the query is

    <?php if(have_posts()) : ?>
    <?php if (is_page()) {
          query_posts("cat=23");
       }
    ?>
    
    <?php while(have_posts()) : the_post(); ?>

    Hope this helps.

  3. cynthea
    Member
    Posted 3 years ago #

    Thanks! I'll try that.

Topic Closed

This topic has been closed to new replies.

About this Topic