Question: I'm working on a WordPress site and I've created a page template that displays posts by a category slug. To do this, I create a field for the page, WP\_Catid, and set it equal to the category slug I want to display posts from. However, I only want five posts to show up per page with pagination links at the bottom of those posts. How do I get the pagination links to display properly?

My code is as follows:

```
<div id="container">
  <div id="content" role="main">
    <?php
      $btpgid=get_queried_object_id();
      $btmetanm=get_post_meta( $btpgid, 'WP_Catid','true' );
      $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

      $args = array( 'posts_per_page' => 5,
                     'category_name' => $btmetanm,
                     'paged' => $paged,
                     'post_type' => 'post' );

      $myposts = get_posts( $args );
      foreach ( $myposts as $post ) : setup_postdata( $post ); 
        echo "<div style='border:2px groove black; margin-bottom:5px;'><h3 class='btposth'>";
        the_title(); 
        echo "</h3><div class='btpostdiv'>";
        the_content();
        echo "</div></div>";
      endforeach; 
      next_posts_link( 'Older Entries'); //not displaying
      previous_posts_link('Newer Entries &raquo;'); //not displaying
      wp_reset_postdata();
    ?>
  </div><!-- #content -->
</div><!-- #container -->

```

Answer: 
[Pieter Goosen's answer](https://stackoverflow.com/a/24847152/988246) is completely correct, and his suggestion to use `WP_Query` instead makes the most sense. However, I stumbled across this question whilst looking for pagination with `get_posts` outside of the loop, so I thought this might also be a useful alternative for anyone else:

`get_posts` has a direct property called [`offset`](http://codex.wordpress.org/Template_Tags/get_posts#Posts_list_with_offset) which achieves pretty much the same thing as `paged` in `WP_Query`; but where `paged` refers to pagination (e.g. *1, 2, 3*), `offset` is the actual *number of posts* you want to offset your query by (e.g. *5, 10, 15*). With a little maths - `numberToShow * pageNumber` - you can get the correct offset easily:

```
$paged = (get_query_var('paged')) ? get_query_var('paged') : 0;

$postsPerPage = 5;
$postOffset = $paged * $postsPerPage;

$args = array(
    'posts_per_page'  => $postsPerPage,
    'category_name'   => $btmetanm,
    'offset'          => $postOffset,
    'post_type'       => 'post'
);

$myposts = get_posts($args);

```

The initial `paged` value in this example is `0` rather than `1` because, when multiplying the `posts_per_page`, you want the initial offset to be `0` rather than `5`. 

This can be most handy if you want a little more granular control rather than straightforward pagination, but should work just as well in combination with the loop in the accepted answer.
WordPress Pagination Code for Posts (NEW)
=========================================

Copy and paste this piece of code and enjoy that. :)

```php
<?php

$currentPage = get_query_var('paged');

// General arguments

$posts = new WP_Query(array(
    'post_type' => 'post', // Default or custom post type
    'posts_per_page' => 10, // Max number of posts per page
    //'category_name' => 'My category', // Your category (optional)
    'paged' => $currentPage
));

// Top pagination (pagination arguments)

echo "<div class='page-nav-container'>" . paginate_links(array(
    'total' => $posts->max_num_pages,
    'prev_text' => __('<'),
    'next_text' => __('>')
)) . "</div>";

// Content display

if ($posts->have_posts()) :
    while ($posts->have_posts()) :
        $posts->the_post();
        echo "<div class='post-wrap'>";
        the_title();
        the_content();
        echo "</div>";
    endwhile;
endif;

// Bottom pagination (pagination arguments)

echo "<div class='page-nav-container'>" . paginate_links(array(
    'total' => $posts->max_num_pages,
    'prev_text' => __('<'),
    'next_text' => __('>')
)) . "</div>";

?>

```