Add paging to category page (6 posts)

  1. vikkineal
    Posted 4 years ago #


    I'm building a website based using wordpress.

    I've got a 'latest news' page which redirects to the post category 'latest news'.

    All of my posts are given the category 'latest news', so as thou can imagine, after a while, this page will become really long.

    How can I add paging to the category page to only show 5 posts per page?

    Here is my code...any pointers would be greatly appreciated.

    <div id="rightColumn">
        <?php if(have_posts()) : ?>
        <?php while(have_posts()) : the_post(); ?>
        <div class="newsResultsPanel post">
          <div class="imgContainer"><a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail($post->ID, 'size-1'); ?></a></div>
          <div class="copyContainer">
            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <h3><?php the_time('F jS, Y') ?></h3>
            <div class="entry">
              <?php the_excerpt(); ?>
            <div class="clearBoth"></div>
            <p class="readMore"><a href="<?php the_permalink(); ?>">Read more ›</a></p>
          <div class="clearBoth"></div>
        <?php endwhile; ?>
        <?php endif; ?>
  2. Michael
    Forum Moderator
    Posted 4 years ago #

    set the number under:
    dashboard - settings - reading - Blog pages show at most [ 5 ] posts

    in your template, after <?php endwhile; ?>
    add some code with:


    example: <?php posts_nav_link(); ?>



    example with html for formatting (extracted from Twenty Eleven):

    <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyeleven' ) ); ?></div>
    			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></div>
  3. vikkineal
    Posted 4 years ago #

    Thank you - is there any way to add paging as numbers rather than next / previous links?

  4. Michael
    Forum Moderator
    Posted 4 years ago #

    use a plugin such as http://wordpress.org/extend/plugins/wp-pagenavi/ or similar.

  5. vikkineal
    Posted 4 years ago #

    Ok - I was hoping to avoid plugins and write something into my functions... I'll take a look at i though.

    Ta :)

  6. Michael
    Forum Moderator
    Posted 4 years ago #

    avoid plugins and write something into my functions

    there is nothing wrong with plugins - and particularly not with wp-pagenavi - as they come with options and styling - but here you go:

    code very much inspired by wp-pagenavi:


    called for instance with:

    <?php if(function_exists('page_navi')) { page_navi(); } else { ?>
    <div class="alignleft"><?php next_posts_link('Older posts'); ?></div>
    <div class="alignright"><?php previous_posts_link('Newer posts'); ?></div>
    <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic