How to: Pages that display all posts from x category
You would like to have all posts from a certain category on a static page. Sometimes with the “more-link” sometimes without. WordPress can do this, but it is tricky and static pages would never shown in feeds.
You would like to have all posts from a certain category on a static page. Sometimes with the “more-link” sometimes without. WordPress can do this, but it is tricky and static pages would never shown in feeds.
» »
Deutsche Anleitung ist hier
You need this for a simple print version for all posts from certain category or for whatever else. My english isn’t the best. So I post the code. You do it and you’ll see the results.
All posts on a static page. Without more-link. No specific category. Sort Order is ASC -eldest post first.
<?php /* Template Name: All */ ?> <?php get_header(); ?> <?php rewind_posts(); $my_query = new WP_Query('order=asc&showposts=500'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; global $more; $more = 1; ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title=" <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small> <div class="entry"> <?php the_content('Read the rest of this entry »'); ?> </div> </div> <?php endwhile; ?> <?php get_sidebar(); ?> <?php get_footer(); ?>
<?php /* Template Name: All */ ?>
Dear WordPress “All” is the name of my static page.
Administration Panels==>Write==>Page==>Title==>right side you can choose this template “All”.
rewind_posts();
Dear WordPress start the loop again. Maybe not necessary but if you have another loop above it is necessary.
global $more; $more = 1;
Dear WordPress show the full post if there is a more-link or not.
$my_query = new WP_Query('order=asc&showposts=500'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?>
Dear WordPress this is my loop. I need all posts. Eldest post first. Give me 500 posts.
Ok I know nobody would like to read 500 posts on one static page.;) But if you would like to have “all” you need a number of posts.
Now all the stuff to show the posts.
<?php endwhile; ?>
Dear WordPress you are ready. The end of the loop.
get header, sidebar, footer -whatever you need for your page.
All posts from a certain category on a static page. With more-link. No specific sort order.
<?php /* Template Name: All */ ?> <?php get_header(); ?> <?php rewind_posts(); $my_query = new WP_Query('cat=10&showposts=500'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; global $more; $more = 0; ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title=" <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small> <div class="entry"> <?php the_content('Read the rest of this entry »'); ?> </div> </div> <?php endwhile; ?> <?php get_sidebar(); ?> <?php get_footer(); ?>
$my_query = new WP_Query('cat=10&showposts=500'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID;
Dear WordPress show me only posts from the category with the id=10.
global $more; $more = 0;?>
Dear WordPress if you will find the more-link in a post please show it.
The rest … » please read above.
You can see the results on my Example Page. Ok there are never ever 500 posts – but you can see it works.

hey! this is a wonderful hack but i want to know the code for next and previous posts of the same category links. please let me know.
sindhu30.12.07 08:39 | # |
how to display from x category and not display from y category?
gamer19.05.08 20:32 | # |
gamer
texto18.06.08 00:40 | # |