Function Reference/posts nav link

跳转至: 导航搜索


Displays links for next and previous pages. Useful for providing "paged" navigation of index, category and archive pages.

For displaying next and previous pages of posts see next_posts_link() and previous_posts_link().

For displaying next and previous post navigation on individual posts, see next_post_link() and previous_post_link().


%%% <?php posts_nav_link( $sep, $prelabel, $nextlabel ); ?> %%%

Note: since weblog posts are traditionally listed in reverse chronological order (with most recent posts at the top), there is some ambiguity in the definition of "next page". WordPress defines "next page" as the "next page toward the past". In WordPress 1.5, the default Kubrick theme addresses this ambiguity by labeling the "next page" link as "previous entries". See Example: Kubrick Theme Format.


(string) Text displayed between the links.
  • Defaults to ' :: ' in 1.2.x.
  • Defaults to ' — ' in 1.5.
(string) Link text for the previous page.
  • Defaults to '<< Previous Page' in 1.2.x.
  • Defaults to '« Previous Page' in 1.5.
(string) Link text for the next page.
  • Defaults to 'Next Page >>' in 1.2.x.
  • Defaults to 'Next Page »' in 1.5


Default Usage

By default, the posts_nav_link() look like this:

« Previous PageNext Page »
<?php posts_nav_link(); ?>

In Centered DIV

Displays previous and next page links ("previous page · next page") centered on the page.

<div style="text-align:center;">
<?php posts_nav_link(' &#183; ', 'previous page', 'next page'); ?>

Using Images

<?php posts_nav_link( ' ', '<img src="' . get_bloginfo('stylesheet_directory') . '/images/prev.jpg" />', '<img src="' . get_bloginfo('stylesheet_directory') . '/images/next.jpg" />' ); ?>

Kubrick Theme Format

The Kubrick theme format for posts navigation, could be formatted this way. However, using posts_nav_link() in this way will result in unintended behavior, such as double stacked next and previous links that link to the incorrect sections.

The Kubrick Theme actually uses next_posts_link() and previous_posts_link().

This is poor code and should not be used:

<div class="navigation">
<div class="alignleft"><?php posts_nav_link('','','&laquo; Previous Entries') ?></div>
<div class="alignright"><?php posts_nav_link('','Next Entries &raquo;','') ?></div>

This is better code:

<div class="navigation">
<div class="alignleft"><?php previous_posts_link('&laquo; Previous Entries') ?></div>
<div class="alignright"><?php next_posts_link('Next Entries &raquo;','') ?></div>

Customizing the Link Text

You can change the text in each of the links and in the text in between the links.

You can go back to the previous page or you can go forward to the next page.
<p><?php posts_nav_link(' or ', 'You can go back
 to the previous page', 'you can go 
forward to the next page'); ?>.</p>


Source File

posts_nav_link() is located in onlyincludecodewp-includes/link-template.php/code/onlyinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Template Description

Link to the source code on


  1. filename
  2. (option) path to codetag/code (version) or codetrunk/code. This option is only used for a new /Default: codetrunk/code -- trunk is the latest bleeding edge development version of WordPress.


Link to the stable version: pre检查到模板循环:模板:Trac/pre

Link to trunk: pre检查到模板循环:模板:Trac/pre




includeonlydiv style=clear:both; background-color:#F7F7F7; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;See also index of Function Reference and index of Template Tags./div/includeonlynoinclude


This Template is used by Codex:Template Messages.


pre 检查到模板循环:模板:Message /pre