How to: Pages that display all posts from x category

Loop Beispiele WordPress
Loop in WordPress

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 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;
 ?>

<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') ?></small>
<div class="entry">
<?php global $more;
$more = 1;
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;
 ?>

<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') ?></small>
<div class="entry">
<?php global $more;
$more = 0;
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.

have fun, do it and please correct my english if you’ll find a or two or more mistakes. I will read a comment or the sky will fall on your head.
2

2 Beiträge zu “How to: Pages that display all posts from x category

  1. Kommentar Autor
    gamer
    Kommentar

    how to display from x category and not display from y category?