Support » Fixing WordPress » How to display one category per page for a particular category in WordPress

  • I am fairly new to WordPress. I am developing a website with a custom theme (I am trying to learn by write one). The website is about automobiles and has categories as bikes, cars, copters etc. I have to display one of the categories (bikes) on the navigation menu. Now when I click on the this menu, it should take me to a separate page which display only the posts about the bikes category. And in this page, I want to display one post per page. So I made a category-8.php (8 being the id of bikes category). So I put the following code in there:

    <?php query_posts( array(  'cat' => 8, 'posts_per_page' => 1  ) ) ?>
    <?php if ( have_posts() ) : ?>
       <?php while ( have_posts() ) : the_post() ?>
          <h3><?php the_title(); ?></h3>
          <h6>BY <?php the_author(); ?> |<?php the_time('F jS, Y') ?></h6>
          <p> <?php the_content(); ?> </p>
       <?php endwhile; // end of the loop. ?>
    <p style="float:left;"><?php next_post_link('%link &laquo; Newer Entries',true) ?></p>
    <p style="float:right;"><?php previous_post_link('Older Entries &raquo %link;',true) ?></p> 
    <?php endif; // end of the loop. ?>

    So the problem here is:

    1. previous_post_link() gives link to another page. I would expect that to give the link to the same page but an older category. Please not the link to this category page is localhost/myBlog?cat=8

    And the previous_post_link points to localhost/myBlog?page=114

    Why is it so? Am I doing something wrong here?

    More importantly, do I need to custom define the page.php or single.php rather than working on category-8.php?

    Any help would be appreciated. Thanks

  • The topic ‘How to display one category per page for a particular category in WordPress’ is closed to new replies.