Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How to get all posts in a category? WordPress

  • SOLVED

I have not worked with WordPress much this last year, and I find I'm forgetting a great deal. Tonight I'm building out a simple design for a friend. [[LINK href="http://dev16.teamlalala.com/GEORGEMcCRACKEN/"]]See here[[/LINK]]. These posts will all belong to the category "collections":

SPRING 2011
FALL 2010
SPRING 2010
FALL 2009

Please remind which function I use to grab all the posts in a category? And how do I customize the HTML that wraps each item?

I am using the newest version of WordPress, 3.1

Answers (2)

2011-02-26

Pippin Williamson answers:


query_posts('category_name=collections');
if (have_posts()) :
while (have_posts()) : the_post();
// post content here
endwhile;
else :
echo '<h3>Oops, something went wrong.</h3>';
endif;
wp_reset_query();


HTML that you want all posts to have will go inside the while loop. HTML that should wrap the posts section goes outside the while loop.

Functions you might want to use inside the loop:

Show the post content: the_content();
Show post title: the_title();
Show post category(s): the_category();
Show post tags: the_tags();

2011-02-26

S├ębastien | French WordpressDesigner answers:


query_posts('category_name=collections');

if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><?php the_title() ?></h2>
<small><?php the_date(); ?> | <a href="<?php the_permalink(); ?>">permalink</a></small>
<div>
<div class="aligncenter"><?php the_post_thumbnail('medium') ?></div>
<?php the_content(); ?>
</div>
<? endwhile; else : ?>
<h3>Sorry. No post.</h3>
<?php get_search_form(); ?>
<? endif;

wp_reset_query();