WordPress.org

Ready to get started?Download WordPress

Forums

Add paging to category page (6 posts)

  1. vikkineal
    Member
    Posted 1 year ago #

    Hiya

    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>
            <div class="clearBoth"></div>
            <p class="readMore"><a href="<?php the_permalink(); ?>">Read more ›</a></p>
          </div>
          <div class="clearBoth"></div>
        </div>
    
        <?php endwhile; ?>
        <?php endif; ?>
    
      </div>
  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year 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:

    http://codex.wordpress.org/Function_Reference/posts_nav_link

    example: <?php posts_nav_link(); ?>

    or

    http://codex.wordpress.org/Function_Reference/next_posts_link
    and
    http://codex.wordpress.org/Function_Reference/previous_posts_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
    Member
    Posted 1 year ago #

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

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

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

  5. vikkineal
    Member
    Posted 1 year ago #

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

    Ta :)

  6. alchymyth
    The Sweeper & Moderator
    Posted 1 year 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:

    http://pastebin.com/9zv36yrR
    http://pastebin.com/M8FBkpin

    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