Support » Themes and Templates » Using query_post to show one category — what am I not getting?

  • I went to the codex and the codex told me how to make a template file display only one category of posts, so I did what it said and I made a new template file based on the index.php template, put query_post in there, and assigned my new template to the page I wanted, which is called performances…when it’s done it will list all posts with category “gig” to function as a list of gigs. But I must be missing something. The performances page just diplays “no posts matched your criteria” even though I do have one post so far with the category Gigs. I tried doing it by query_posts(‘category_name=’gigs’) also. The codex said to put query_posts before the LOOP and I tried it in a couple different places in the code to see if that made a difference.

    Please give me a hand, if you know what to do here. The site I’m working on is at The template I made looks like this:

    Template Name: All Gigs Template

    <?php query_posts(“category=6”); ?>

    <?php get_header(); ?>

    <div id=”content” class=”narrowcolumn”>

    <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

    <div class=”post” id=”post-<?php the_ID(); ?>”>
    <h2>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></h2>

    <div class=”entry”>
    <?php the_content(‘Read the rest of this entry »’); ?>


    <?php endwhile; ?>

    <div class=”navigation”>
    <div class=”alignleft”><?php next_posts_link(‘« Previous Entries’) ?></div>
    <div class=”alignright”><?php previous_posts_link(‘Next Entries »’) ?></div>

    <?php else : ?>

    <h2 class=”center”>Not Found</h2>
    <p class=”center”>Sorry, but you are looking for something that isn’t here.</p>
    <?php include (TEMPLATEPATH . “/searchform.php”); ?>

    <?php endif; ?>


    <?php get_footer(); ?>

    —end of code—

    A separate, possibly related issue is that I can’t view individual pages from the MANAGE –> PAGES area of the dashboard unless I change the permalinks back to the default setting. I CAN view them using the links I made to them, when the permalinks are set the way I want, for example I am linking to in my header, but then I can’t view individual posts. That is the way it is now, if you go look at what I have so far.

    Thanks for any wisdom!


    Zack Kline

Viewing 2 replies - 1 through 2 (of 2 total)
  • Regarding the first part, why not use Category_Templates if you want to show posts from only one category?

    They’re built-in to WP, no hackery necessary. 🙂

    Thanks Handy. That was a good solution for now. I will need to, later, sort the gigs posts by date they are happening, not date they are posted. I think EventCal can do that on a page…I know it can do it on a sideabar,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using query_post to show one category — what am I not getting?’ is closed to new replies.