Herself's Webtools

Scripts, HowTos, Templates, Plugins, Widgets, Tips

How to create a list of posts by category in WordPress

with 2 comments

I have to say creating a link lists of posts by category in WordPress is downright painful. To create the archive list ( see link near search box on sidebar ) you need a list of your categories, the category number. You will use these to create an archives.php page.

1) A list of your categories can be found by going to the Dashboard, then drop down the Posts menu and select categories.  These are the headings you put between the <br><h3>Category Name</h3> in the php below.

2) Category numbers had to be dug out of my database.  I used MySQL Admin, went to my WordPress database.  Select your database, find the wp_terms table and click on the leftmost icon under ‘Action’ to list your tags and categories. The link_id is the category number.

3) PHP code copy and paste this to a file named Archives.php.  Change the category names and numbers to match those on your website.  Also add or delete as many categories as you need. Your template is likely different than mine you may need to adjust the sidebar, footer etc to match your template’s style

4) showposts=200 is the maximum number of posts it will show in that category, adjust if you need to.

<?php
/*
Template Name: Archives
*/
?>

<?php get_header(); ?>

<div id=”content”>

<h2>Archives</h2>

<div>

<p>Complete archive of the blog’s posts sorted by category</p>

<br><h3>Fun things to do in Houston</h3>
<?php query_posts(‘cat=5&showposts=200′); ?>
<?php while (have_posts()): the_post(); ?>
<li><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></li>
<?php endwhile; ?>

<br><h3>OMG We’re in Texas</h3>
<?php query_posts(‘cat=7&showposts=200′); ?>
<?php while (have_posts()): the_post(); ?>
<li><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></li>
<?php endwhile; ?>

<br><h3>The Move</h3>
<?php query_posts(‘cat=15&showposts=200′); ?>
<?php while (have_posts()): the_post(); ?>
<li><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></li>
<?php endwhile; ?>

<br><h3>This ‘n That</h3>
<?php query_posts(‘cat=14&showposts=200′); ?>
<?php while (have_posts()): the_post(); ?>
<li><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></li>
<?php endwhile; ?>

<br><h3>Tokyo Trip</h3>
<?php query_posts(‘cat=172&showposts=200′); ?>
<?php while (have_posts()): the_post(); ?>
<li><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></li>
<?php endwhile; ?>

<br><h3>Geekiness</h3>
<?php query_posts(‘cat=83&showposts=200′); ?>
<?php while (have_posts()): the_post(); ?>
<li><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></li>
<?php endwhile; ?>

<br><h3>Photos</h3>
<?php query_posts(‘cat=10&showposts=200′); ?>
<?php while (have_posts()): the_post(); ?>
<li><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></li>
<?php endwhile; ?>

</div>
</div>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

5) Upload your archives.php file to your theme directory on your webserver.

6) Finally create a new page – drop down the attributes menu on the right and select archives as your template

Or if you’d rather there’s a new plugin out to do display all posts in all categories for you James Wilkes Web Design

Written by Linda MacPhee-Cobb

April 2nd, 2010 at 11:51 am

Posted in archives,hack your template,how to,php,wordpress,wordpress template

2 Responses to 'How to create a list of posts by category in WordPress'

Subscribe to comments with RSS

  1. Hi! Thank you very much your info. I have searched for the topic and found your website. Now I have already finished my All Posts by Category with some adjustment. I also use the template Journalist! I think I am going to copy some of your ideas for my website. :-p Thank you very much again. Your website is very cool and beautiful.

    Mat

    1 Jan 11 at 9:21 am

  2. Glad to be of assistance. I love your domain name ( http://www.english-love.com/ )

    timestocome

    5 Jan 11 at 8:33 pm

Leave a Reply

You must be logged in to post a comment.