query posts problem
-
Hi there. I have a wordpress site, and I need the main page to only display posts from one category. I’ve used “query posts” before with success, so I tried putting this right after the head, on the index.php page (as I did before):
<?php if (is_home()) { query_posts("cat=2"); } ?>And it does indeed display posts from Category 2 first, but then I get two instances of an error (I happen to have 2 other posts, in a different category), you can view the results here:
http://www.slowpitchpr.com/wp/
Very strange, and everything works without that query posts bit (it just displays all posts)… Here is the code for the index.php file, I’m thinking something is not structured correctly here:
<?php get_header(); ?> <div id="main"> <div id="content"> <?php if (is_home()) { query_posts("cat=2"); } ?> <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?> <div class="post"> <p class="cat"><?php the_category(', ') ?></p> <h2 class="post-title"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a> </h2> <div class="post-content"> <?php the_content('Continue Reading »'); ?> <?php wp_link_pages(); ?> <!-- <?php trackback_rdf(); ?> --> </div> <p class="post-info"> <em class="date"><?php the_time('d M Y'); ?></em> <em class="user"><?php the_author_posts_link() ?></em> <span><?php edit_post_link(); ?></span> <span class="post-comments"><?php comments_popup_link('0 comments', '1 comment', '% comments','','comments off'); ?></span> </p> <?php comments_template(); ?> </div> <?php endforeach; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> <p align="center"><?php posts_nav_link(' - ','« Prev','Next »') ?></p> </div> <?php get_sidebar();?> <?php get_footer();?>
The topic ‘query posts problem’ is closed to new replies.