Support » Fixing WordPress » Step-by-step needed: page displaying a list of posts in a category

  • Resolved TheOrganicSister


    I’ve seen a couple topics on how to have a page pull a category but I don’t quite understand how to do it.

    Can someone post a step-by-step of how to do it for a codex beginner? What code to use, what to change in the code, where to put it?

    Thank you in advance,

Viewing 2 replies - 1 through 2 (of 2 total)
  • 1. Read Pages.
    2. Read about the template tag, query_posts().
    3. Create a Page Template like this in your theme folder. Save it as currently_playing.php:

    Template Name: CurrentlyPlaying
    	<div id="content" class="narrowcolumn">
    $cat=get_cat_ID('Currently Playing'); // get a category ID
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts ('cat='.$cat.'&showposts=1&paged=' . $paged);
    	<?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?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 &raquo;'); ?>
    				<p class="postmetadata"><?php the_tags('Tags: ', ', ', ''); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
    		<?php endwhile; ?>
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    	<?php else : ?>
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.
    		<?php get_search_form(); ?>
    	<?php endif; ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    4. Create a Page called Currently Playing, and assign the Page Template CurrentlyPlaying you just created.

    For this example using the WordPress Default Theme, so the template in Step 3 was placed in the wp-content/themes/default folder. Also have a category called ‘Currently Playing’. Of course you just need to replace Currently Playing with whatever you want to call it. Just so you know, the Page Template and the Page name don’t need to be the same as the category name.

    Thanks for this. I actually found an easier route. I placed a hyperlink to the category in the page title. Worked like a charm. I wil save this though in cse I need it in the future. Thanks again. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Step-by-step needed: page displaying a list of posts in a category’ is closed to new replies.